cell().invalidate()
Invalidate the data held in DataTables for the selected cells.
Description
DataTables holds cached information about the contents of each cell in the table to increase performance of table operations such as ordering and searching. If you were to modify the contents of a cell (for DOM data source tables) or the array / object values (for Ajax / JS source tables) DataTables wouldn't know that this has happened. This method can be used to tell DataTables to re-read the information from the data source for the row (be it from the DOM or objects / arrays - whatever the original data source was).
This provides an alternative to using cell().data()
and row().data()
when changing cell values. Typically the data
methods are preferred over the invalidation methods, as they use less code, but where the invalidation methods really shine is when the data source for the table are external objects which can be updated using that objects' own methods.
Prior to DataTables 1.10.4 this method actually invalidated the whole row. As of 1.10.4 only the cell in question is invalidated.
Type
function cell().invalidate( [ source ] )
- Description:
Invalidate information in the selected cell
- Parameters:
Name Type Optional 1 source
Yes - default:auto Data source to read the new data from.
By default, DataTables will automatically read the new data for the row from the same source as it was originally read (i.e. DOM sourced or Javascript sourced) but this parameter can be used to override that and tell DataTables specifically which should be used to read in the new data. This might be useful if you are Ajax loading data but use the DOM to modify the contents of cells.
This property can take the values:
auto
- use original data sourcedata
- use the Javascript data structuredom
- use the data currently held in the DOM
- Returns:
DataTables API instance with selected cell reference in the result set
Example
Increment a cell's value and then invalidate and redraw the table:
var table = new DataTable('#myTable');
$('#example tbody').on('click', 'td', function () {
this.innerHTML = parseInt(this.innerHTML) + 1;
table
.cell(this)
.invalidate()
.draw();
});
Related
The following options are directly related and may also be useful in your application development.