I am having a DT with a working custom column filter that gets triggered by a <SELECT> drop down in the footer of one column. Depending on the value of the drop down it either shows all rows, rows with column value 0, or rows with column value >0.
The <SELECT> on change triggers a oTable.fnDraw() which has a $.fn.dataTableExt.afnFiltering.push() function attached.
I am struggling to set the default filter when page/table is loaded first time to filter value>0. I tried to trigger a change event on the drop down box after page is loaded, and also using fnInitComplete but despite no error in console still all data is shown.
Any ideas / workarounds?
thx
Martin
The <SELECT> on change triggers a oTable.fnDraw() which has a $.fn.dataTableExt.afnFiltering.push() function attached.
I am struggling to set the default filter when page/table is loaded first time to filter value>0. I tried to trigger a change event on the drop down box after page is loaded, and also using fnInitComplete but despite no error in console still all data is shown.
Any ideas / workarounds?
thx
Martin
$(document).ready(function() { var oTable = $('#table_main').dataTable( { "fnInitComplete": function(oSettings, json) { $('#sel_search_positions').val('zero').change(); } }); //Select button that wil trigger the filter function by current positions $('#sel_search_positions').change( function() { oTable.fnDraw(); }); //filter function that gets triggered by column 3 select drop down (see above) $.fn.dataTableExt.afnFiltering.push( function( oSettings, aData, iDataIndex ) { //filter on current position which is column 3 for example colFilterID = 3; //get our filter element filterElement = aData[colFilterID]*1; //get our filter critera from the SELECT drop down in footer of column filterCriteria = $('#sel_search_positions').val(); //CURENT: based on SELECT field sel_search_positions decide how to filter if(filterCriteria == 'current') { //filter on current values only if(filterElement > 0) { return true; } return false; } //ZERO: based on SELECT field search_curr_pos decide how to filter if(filterCriteria == 'zero') { //filter on not current stock values only, e.g. where current Position is zero 0 if(filterElement == 0) { return true; } return false; } //ALL: based on SELECT field search_curr_pos decide how to filter if(filterCriteria == 'all') { //show all value regardless return true; } } ); ..... <tfoot> <tr> <th colspan="4"> <select id="sel_search_positions"> <option value="current">Current Pos</option> <option value="zero">No Positions</option> <option value="all">Show All</option> </select> </th> ........ normal table