cyberhobo / ColumnFilterWidgets

This is an add-on for the DataTables plugin for jQuery that creates filtering widgets based on the data in table columns.
69 stars 34 forks source link

ColumnFilterWidget.prototype.fnDraw on table redraw slows loading, sorting, etc #40

Open recarv opened 9 years ago

recarv commented 9 years ago

When dealing with large datasets, the performance slowdown on re-populating the select dropdowns on any change in the datatable redraw is significant and the cost is exponential. In a test on a table with 10 columns and 11k rows, the load time goes from 8sec to 25sec in Firefox (no firebug). Furthermore when using the sorting plugin and sorting, this triggers a redraw which slows down sorts significantly as well.

While I understand the helpfulness of maintaining updated filterable values, I would recommend adding a way to make this function called more selectively and leave that option up to the developer to trigger manually - such as on a filter selection.

I've commented out the fnDraw() below and this greatly speeds loading and sorts.

oDataTableSettings.aoDrawCallback.push( { name: 'ColumnFilterWidgets', fn: function() { $.each( me.aoWidgets, function( i, oWidget ) { //oWidget.fnDraw(); } ); } } );

DjTrilogic commented 8 years ago

I encountered the same symptoms with large data sets: its too much time costing to re-populate the widget selects on each table redraw (this affects paginating aswell...).

I'd rather trigger the widget redraw on data manipulation events such as a search callback (with a delay to prevent the same problem occurence while typing in the search bar for example)...

I will investigate this problem and create a pull request once i have a viable solution.

cyberhobo commented 8 years ago

Thanks guys, I'm happy to look at a pull request. It looks like removing the draw breaks updating widgets to contain only valid values for the current filters, but there are probably more efficient ways to achieve that.