I'm using the jquery.datatables plugin along with the FixedColumns add-on and am experiencing some issues keeping the two tables in sync.
The first 2 rows of my table contain checkboxes.
Since the data is ajax loaded I returned "true" or "false" values in the JSON for the checkboxes and I would use fnRowCallback
to dynamically create and replace the "true" or "false" with the appropriate checkbox.
Then I added the FixedColumns add-on and although the table initially loads correctly, subsequent redraws do not replace the "true" or "false" values with checkboxes.
Although fnRowCallback
still fires, it only has part of the table and only part of the data
Note this code is in TypeScript but resembles JS closely enough to understand without knowing it
fnRowCallback: (row : DataTables.Settings, data: any[], displayIndex: number, displayIndexFull: number) : void => {
if($(row).children("td.checkboxColumn").length > 0){
var isFlaggedIdentifier = 'isFlaggedCheckbox_' + displayIndexFull;
var isFlaggedCheckbox = $('<input />', { type: 'checkbox', id: isFlaggedIdentifier, 'class': 'tableCheckboxInput', value: isFlaggedIdentifier });
var isFlaggedLabel = $('<label />', { 'for': isFlaggedIdentifier, 'class': 'tableCheckboxLabel' });
var isFlagged: bool = $(row).children("td").eq(1).text() === "TRUE";
var flaggedCheckboxEntry = $(row).children("td").eq(1);
if(flaggedCheckboxEntry.hasClass("checkboxColumn")){
flaggedCheckboxEntry.html(isFlaggedCheckbox);
flaggedCheckboxEntry.append(isFlaggedLabel);
}
}
}
According to docs it seems FixedColumns doesn't have an fnRowCallback
. It only has fnDrawCallback
which only fires once after the table it drawn so although I havent tried it I fear it will cause the "true"/"false" to flash before being replaced by checkboxes.
If this assumption is true what can I do to replace the checkboxes before the table is rendered.