Search code examples
javascriptangularjshandsontable

Handsontable: Rerender a cell after updating the cell's meta?


After each cell change, I am sending the cell's content to the backend, getting updated meta object and am applying it to the cell. The new meta object holds a different colour for the renderer. I need to retrigger cell rendering after I've set the meta data. I found the event afterSetCellMeta() but I can't find a way to rerender a single cell only. Just for reference, this is the function I am using:

function updateCell(data) {
  var i = 0;
  var to = data.length;

  for (i; i<to; i++) { // Go trough all changed cells, update their meta object.
    var row = data[i].row;
    var col = data[i].col;
    var metaObject = data[i];
    console.log('About to set: ', metaObject);
    vm.hot.setCellMetaObject(row, col, metaObject);
    // I need to update the renderer here.
  }
}

Anyone had done that? Any ideas are appreciated, since I'm out of any.


Solution

  • Handsontable doesn't just re-render a single cell. Any event that triggers a change will re-render the entire table. This is done on purpose to make sure the table is "state-less" and always reflecting what the data represents. With that said, what's the problem with re-rendering the whole table? It should be pretty quick since HOT uses virtual rendering but are you seeing issues there?

    If what you mean is that you want to update your renderer, then where you have that comment on updating the renderer you can insert:

    hot.updateSettings({
        cells: newCellsDefinition // here you would define a new renderer for whatever cells you want to change the renderer for
    });