Reputation: 3610
I am using DataTables to create a table. After I init the table, I would like to change some settings that control how one of the columns is rendered, like so:
var st = mytable.dataTable().fnSettings();
$.extend(st.aoColumns[2], {
"mRender": function (val, type, row) {
return "xxx";
}
});
But when I load the page, I get: "object is not a function inside DataTables.js:181 (marked below with "this is the error line"):
/* Cache the data get and set functions for speed */
var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
var mData = _fnGetObjectDataFn( oCol.mData );
oCol.fnGetData = function (oData, sSpecific) {
var innerData = mData( oData, sSpecific );
if ( oCol.mRender && (sSpecific && sSpecific !== '') ) {
return mRender( innerData, sSpecific, oData ); <== this is the error line
}
return innerData;
};
Seems like some caching mechanism is assuming the mRender value will not change after init, but in fact DataTables allows external settings manipulation via the fnSettings method, which explicitly documents that it is for "external manipulation".
Any ideas on how to resolve this?
Upvotes: 1
Views: 1419
Reputation: 3610
Ok found the solution - use aoColumnDefs instead of aoColumns, and specify the column targets in aTargets array:
var aoColumnDefs = [{
"mRender": function (val, type, row) {
return "xxx";
},
"aTargets":[2]
}];
mytable.dataTable({aoColumnDefs:aoColumnDefs});
Upvotes: 1