How to remove a fnFilter() and display all results?

How to remove a fnFilter() and display all results?

thehman7thehman7 Posts: 4Questions: 0Answers: 0
edited December 2011 in DataTables 1.8
Hello-

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!

Here is my code:
[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();
});
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    oTable.fnFilter(''); should be all that is needed. You can see that here, where the filter is cleared after 1 second: http://live.datatables.net/ucodaz/edit .

    I don't see an obvious reason why your code won't work. A javascript error on the console perhaps?

    Allan
  • thehman7thehman7 Posts: 4Questions: 0Answers: 0
    Hi Allan-

    There were no errors in the console. However, I did seem to isolate 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.
  • thehman7thehman7 Posts: 4Questions: 0Answers: 0
    edited December 2011
    Ah I seemed to have figured it out.
    Have to clear out the filter on that specific column AND the global filter:
    [code]
    oTable.fnFilter('',7);
    oTable.fnFilter('');
    [/code]
This discussion has been closed.