Force DataTable Draw but getting data again from the ColumnsDefs function
Force DataTable Draw but getting data again from the ColumnsDefs function
Hi there,
I have a table with a columnDefs function similar to this below...
"columnDefs": [
{
"targets": [iVenAmt],
"mData": function (source, type, val) {
if (type === 'set') {
source.VendorTotal = val;
return;
}
else if (type === 'display') {
return Currency(VendorAmt(source));
}
else if (type === 'filter') {
return VendorAmt(source);
}
else if (type === 'sort') {
return VendorAmt(source);
}
else return VendorAmt(source);
},
"sClass": "text-right"
},
the function VendorAmt gets its data from two different places in the underlying data depending on a filter switch on the form.
If I do a oTable.Draw() on the form after a filter has been applied using
$.fn.dataTableExt.afnFiltering.push(function (oSettings, aData, iDataIndex) {
//filtering code here
})
$("#myTable").dataTable().fnDraw();
the resulting table will redraw, but not using the else if (type === 'display') in the columnDefs function
however it columnDefs will be used if I sort on the column.
My question is there anyway I can do a refresh or something that will force the use of the columnDefs 'display' again?
my data is loaded in from an Ajax call, has over a thousand records and comes from a very complex store proc, so just recalling the Ajax isn't really an option I'd like to use?
Any help appreciated... thank you
Jason
This question has accepted answers - jump to:
Answers
You need to use the
cell().data()
orrow().data()
methods to set the data which will cause the display value to be updated. Otherwise DataTables just uses the display value that it havs previously used since it doesn't know that the data has changed.cell().invalidate()
androw().invalidate()
are two other functions that could also be used.Allan
Column().invalidate() could be a good one, just saying, allows the user to invalidate an entire column..
Yes, I've wondered about that in the past... It will probably be in a future version.
Allan
thanks for the help and time