Search code examples
jquerytabulator

Highlight Tabulator cell which its value is updated


If have a Tabulator table and dynamically update or add new rows to it. I want to highlight the cells in existing rows which their values are changed. Let's say my table object is myTable, I wrote below lines:

myTable.updateOrAddData(fieldsData).then(function (rows) {
    for (var key in rows[0]['_row']['cells']) {
        if (rows[0]['_row']['cells'].hasOwnProperty(key))
            if (rows[0]['_row']['cells'][key]['oldValue'] != null) {
                // Now get the element of the current cell and apply jQuery highlight to it
            }
    }
});

How should I get the cell element?


Solution

  • Below code worked for me to access the element of the cell which is changed as the row is updated:

    myTable.updateOrAddData(row).then(function(rows) {
      try {
        for (var key in rows[0]['_row']['cells']) {
          if (rows[0]['_row']['cells'].hasOwnProperty(key))
            if (typeof rows[0]['_row']['cells'][key]['oldValue'] != 'undefined' && rows[0]['_row']['cells'][key]['oldValue'] != null) {
              var cell = rows[0]['_row'].getCell(rows[0]['_row']['cells'][key]['column']['field']); // specify the column to get the cell of
              $(cell['element']).effect("highlight", {
                color: '#329cff'
             }, 1000); // highlight effect for 1 second
            }
        }
      } catch (e) {}
    });