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

oDataTable.fnVersionCheck issue #36

Closed skarv closed 9 years ago

skarv commented 9 years ago

In the current code, the version check for DataTables determining whether to use the fnGetColumnData function or the new "search: 'applied'" method is phrased like this:

if( widget.oDataTable.fnVersionCheck( '1.10.0' ))

This performs the check for each fnDraw operation. Since the version of DataTables will not change between draw operations, you could check against a set variable instead, such as this:

var usefnGetColumnData = true
var dataTableVersion = $.fn.dataTable.version.split('.');
if (parseInt(dataTableVersion[0]) > 0 && parseInt(dataTableVersion[1]) > 0 ) usefnGetColumnData = false  

and in the 'ColumnFilterWidget.prototype.fnDraw' function, replace the fnVersionCheck line with the following if ( usefnGetColumnData === false ), making the final check look like this:

if ( usefnGetColumnData === false ) aData = widget.oDataTable.api().column( widget.iColumn, { search: 'applied' } ).data().sort().unique();
else aData = widget.oDataTable.fnGetColumnData( widget.iColumn );