5

I have some handsontable which I use to update information into the db.

The first step is: I validate the data, then if an error occurred I fill the row with red color else I just save the information

Here come the problem:
I call ajax request hard coded I change the style of the td or tr But after I change some value or use the scroll in the table, it calls the inside draw function, and all the colors are backto default

How Do I set the cell to be invalid ?

Mel
  • 5,837
  • 10
  • 37
  • 42
user3301396
  • 73
  • 1
  • 6

2 Answers2

8

On version 0.21, maybe newer version than the other answer, this is what worked for me, and seems a bit cleaner:

myHandsOnTable.setCellMeta(rowIndex, colIndex, 'valid', false);
myHandsOnTable.render();

https://docs.handsontable.com/0.21.0/Core.html#setCellMeta

Andrew
  • 18,680
  • 13
  • 103
  • 118
5

You can use the method 'getCellMeta(row, col') to get the cell data then edit the property 'valid' of that cell.

e.g.

var cellMeta = $("#table").handsontable('getCellMeta', row, col);
cellMeta.valid = false;
// Force re-rendering
$("#table").handsontable('render');

The getCellMeta(row,col) method only accept numeric parameters. Do not put the property name of your object as column number.

Best regards,

sn1987a
  • 201
  • 1
  • 6