Set default filter on first load?
Set default filter on first load?
I am not using the built in search. I have my own form above the grid. I am using Knockout to bind that form to an object. When the user presses search, I am calling "searchResultsTable.fnFilter(ko.ToJSON(searchCriteria);". This is passing the full json for my criteria to the server where I parse it and apply the filter.
Problem is sometimes, I have an initial filter in place. But I don't know how to get this json into the table. If the user clicks on a column to sort, that filter json is not getting passed to the server.
But if the user changes the filter, searches, my method above is called, the sort and the filter json are passed to the server. If the user then clicks to sort, the filter json is still included in the call to the server.
So how can I get the default state of my filter into the grid when it's first created?
Problem is sometimes, I have an initial filter in place. But I don't know how to get this json into the table. If the user clicks on a column to sort, that filter json is not getting passed to the server.
But if the user changes the filter, searches, my method above is called, the sort and the filter json are passed to the server. If the user then clicks to sort, the filter json is still included in the call to the server.
So how can I get the default state of my filter into the grid when it's first created?
This discussion has been closed.
Replies
Allan
jqFilter.val( oPreviousSearch.sSearch.replace('"','"') );
oPreviousSearch contains my json string and sSearch is null;
I am using an ajaxSource and it's my server that knows how to process the search criteria.
[code]
$('#example').dataTable( {
"oSearch": {
"sSearch": "mySearchValue"
}
} );
[/code]
DataTables search expects a string input (how would a user input a JSON search string?). If you need to send extra data to the server in the Ajax request then you can use fnServerParams .
Allan
My problem was I was just setting my json string into oSearch directly.
The user doesn't input a json string, but the user does use MY custom search interface and that wraps everything up into json. I will still look into fnServerParams for other data that I need to get across.
I tried the code but my result is displaying based on the default test.How can i avoid this.Please hel me...
Allan