Columns().Visible() Function Terribly Slow with Large Tables
Columns().Visible() Function Terribly Slow with Large Tables
Hi again.
With tables of many columns, the visible() function can become terribly slow, even when redrawCalc option is set to false.
Ref: columns().visible().
This code line hides all columns with header class = 'empty': table.columns('.empty').visible(false, false);
In the simple example I built, which contains 20 rows, if the table has 60 columns ... no problem. You can toggle the empty class columns in a fraction of a second.
Here is link to 60 Column Example. Click "Toggle Position Columns" button to demo.
But when the same table has 600 columns, the time to complete the toggle is 50 seconds!
Here is link to 600 Column Example.
It would actually be faster to rebuild the table from scratch than use the dt visible() function.
Is there better way to implement this function? My tables can reach over 1000 columns. At that point, attempting any ColVis is hopeless.
Thanks in advance, as always.
c
Replies
If instead of using columns().visible(), I reinitialize the table, rebuilding the html to eliminate class = 'empty' columns, it toggles in under 2 seconds ... 600 columns and 20 rows!
Here is link to 600 Column ReInitialize Example.
Thanks for the test case - that made working on this easier
.
I've committed a change to Buttons and also to DataTables core to help improve performance. Note the DT commit was on the 2.3 branch which I aim to release later this month. The changes involve:
In your example the original click event handler time on my computer was 32.5S (31.9S shown on the in page timer you put in). With the modifications it is down to 1.1S (0.6S in page - the rest is the column width recalculation).
It still isn't blazingly fast, but it is at the point now of needing to change the DataTables API to be prototype based to reduce this much further. I do plan to do that at some point (v3 probably), but that is likely some time out!
Allan
Thank you, Allan. 32 sec to 1 sec will make all the difference. Through the years, I've so embedded the columns().visible() function ... an embarrassing amount. I could move away from it, but it would be ugly and long. Glad and relieved to hear about the upgrade and look forward to implementing it. Very much appreciate all you do. c
"Note the DT commit was on the 2.3 branch ..."
Hi Alan, any chance we could preview this in the nightly drops?
Ref: https://datatables.net/download/nightly
Yes, soon. I'm not quite ready to merge 2.3 to master, but I expect it won't be too long. Possibly next week.
Allan