in jqgrid, why dont toolbarfilter and Multiple Search filter get along (when using stringResult:true)
i have a website with jqgrid and I want to use both:
- Toolbar Searching
- Advanced Multi searching (using multip开发者_如何学PythonleSearch: true)
I am using toolbarfilter setup using:
$("#grid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true })
So, this way, users have 2 ways of filtering.
My issues are:
Toolbar Text does get removed after advanced filter (and is not factored into search request)
If i have a toolbar search and hit enter. works great. If i then use click on the advance multi search and enter some criteria, it will "overwrite" the filter criteria BUT it leaves the text in the toolbar filter bar so when you see the results it confusing as the result set doesn't match with what you see in the toolbar filter text.Going back and forth doesn't respect each other I set up initial advance multiple filter set, it works great. I then enter some text in the toolbar filter and hit enter, it sends ONLY that filter form the toolbar to the server (thus overwriting the existing filters set from the advance filter - which are now gone). If i go back to the advanced filter, it lists the old filter that i initially sent (not the latest filter that was generated from the toolbar filter). Is there anyway toolbarfilter and advancedfilter can work together and always build up a cumulative filter from both UI inputs, instead of overwriting each others in the request to the server.
So basically in both use cases above it seems like you are not supposed to use both forms of filtering together as they don't seem to play nice together.
Update:
this image is in response to Oleg's first answer:
All you do is absolutely correct. I would recommend you to continue to use the same configuration: the toolbar filters for the quick, intuitive and easy data searching/filtering and advance searching for the advance searching to make more complex filters.
In the current version of jqGrid the advance searching module use postData.filters
to load the initial filters. The toolbar filter searching on the other side don't read the data from the postData.filters
and just set it.
If you do want to hold separate filters for the toolbar and advance searching I can suggest the the following trick. You can open the advanced filter direct after the grid initialization. The adnavce searching module read the postData.filters
at the first dialog opening only if the default settings recreateFilter: false
and loadDefaults: true
are used. After the opening you can immediately close the searching dialog which will be only disabled and not removed.
var grid = $("#list"), prmSearch = {multipleSearch:true,overlay:false};
grid.jqGrid({
// ... jqgrid parameters
});
grid.jqGrid('navGrid','#pager',
{add:false,edit:false,del:false,search:true,refresh:true},
{},{},{},prmSearch);
// open the advance searching dialog
grid.searchGrid(prmSearch);
// close the advance searching dialog
$("#fbox_"+grid[0].id+" div.ui-closer").trigger("click");
grid.jqGrid('filterToolbar',{defaultSearch:'cn',stringResult:true});
So you can use now both toolbar and advanced searching with separate filters. Because of the usage of the overlay:false
parameter in the searching dialog you can even reset the grid filters in the toolbar searching without closing the advance searching dialog.
You can see the corresponding demo live here.
UPDATED: One more demo use toggleToolbar to hide filter toolbar if the advanced dialog will be opened and show it if the advanced dialog will be closed.
UPDATED 2: In another answer you will find how to delete the last line of the searching dialog (with "Inv No") which are not the part of the searching rules from the postData.filters
. The new version of the demo is here.
精彩评论