Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery DataTables - Remove fnFilter and display all results

I current have a datatable that has a button for each record that when clicked displays other information for that account. When this happens, I call fnFilter() to filter that specific row so that no other ones are displayed and the user knows that the sub-information I display is for that specific account. What I would like to do, is when a user clicks back in the search toolbar, it hides the sub-information I displayed, then clears the filter and shows all the original records available. Everything works fine, except that the filter doesnt get cleared so only the originally selected row is still displayed.

Not sure what I am missing. I have tried everything from using fnFilter(''), to fnDraw(), to fnReloadAjax(). None of these (or any combination) seem to work!

UPDATE I seemed to have isolated the problem. If I remove the column # from the fnFilter(accountid,7), using fnFilter('') does re-display all records. However, I really need to filter by that specific column as it is the only column that contains unique values for each record. Any ideas? I did try using fnFilter('',null) but no success.

Here is my code:

var oTable = $('.mypbhs_accounts').dataTable({         "bProcessing": true,         "sAjaxSource": 'sql/mypbhs_accounts.php',               "aaSorting": [[1, "asc" ]],         "bJQueryUI": true,         "sPaginationType": "full_numbers",         //"bStateSave": true, //Use a cookie to save current display of items         "aoColumns": [             {"asSorting": [  ], "sClass":"center"},             null,             null,             null,             null,             null,             null,             { "bSearchable": true, "bVisible": false },                    { "bSearchable": true, "bVisible": false }                ],         "bScrollCollapse": true,         "sScrollX": "100%",          "fnInitComplete": function() {                 oTable.fnAdjustColumnSizing();          }     }); /*** CLEAR CURRENT ACCOUNT INFO ***/ $(document).on('click','.mypbhs_content .dataTables_filter',function(){ //THIS IS CALLED WHEN USER CLICKS INTO THE SEARCH BAR     $('.mypbhs_content .dataTables_filter :input').val(''); //CLEAR CURRENT VALUE IN THE SEARCH BAR     oTable.fnFilter('');     //oTable.fnDraw();     //oTable.fnReloadAjax();     $('.mypbhs_truform_info').empty(); //REMOVE SUB-INFORMATION SO IT DOESNT GET ASSOCIATED WITH WRONG ACCOUNT     $('.control_bar').children('ul.mypbhs_account_controls').empty(); }); 
like image 691
JimmyJammed Avatar asked Dec 07 '11 21:12

JimmyJammed


1 Answers

Ah I seemed to have figured it out. Have to clear out the filter on that specific column AND the global filter:

oTable.fnFilter('',7); oTable.fnFilter(''); 
like image 193
JimmyJammed Avatar answered Oct 26 '22 23:10

JimmyJammed