Enhancement: Index column example
Enhancement: Index column example
In the Index column example the code works fine.
However when used together with Buttons extension the index column doesn't get printed and doesn't appear in PDF and CSV files.
The solution is to call cell().invalidate()
API method after updating the DOM.
t.on( 'order.dt search.dt', function () {
t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i + 1;
t.cell(cell).invalidate('dom');
} );
} ).draw();
I'm proposing to modify the example above and correct the code accordingly. However it may be not optimal solution in case of large datasets.
See this jsFiddle for demonstration and related discussion on Stack Overflow.
This question has an accepted answers - jump to answer
Answers
Good point - thanks for suggesting this. Let me have a little think about it before I drop it in. I can see it could be useful, but also potentially confusing for new comers.
Allan
Please note that I haven't tested it with large dataset, invalidating cell data on a search or sorting may not be the best idea.
This is only needed when data is exported. So now that I think of it, it maybe not the best solution. Instead I would invalidate the data once on data export. But I can't seem to find an easy way to call invalidate before the PDF/CSV export.
That probably would be a better option. It might be best for the buttons to trigger some kind of
preAction
event that can be listened for and whatever updated required are triggered.Allan
Having
preAction
would be the better. Or maybe returntrue
inaction
callback to proceed with default action orfalse
to cancel default action for built-in buttons. That would be more logical and would not require extra option.My idea for a workaround is to use
button().action()
to save current action and then call this saved function after invalidation is made.