0

i have a website with jqgrid and I want to use both:

  • Toolbar Searching
  • Advanced Multi searching (using multipleSearch: 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:

  1. 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.

  2. 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: enter image description here

leora
  • 188,729
  • 360
  • 878
  • 1,366

1 Answers1

2

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Oleg - i added an image above. I don't necessarily want them to have seperate filters. I want them to either 1. overwrite the UIs of each other to be consistent (what you see matches the data filter) or 2. to treat them different and take the rules on one plus the rules on the other one and have that be the filter rules. I guess the issue is if you see conflicting rules on the same column (as per the image) i would expect it either change the text in the toolbar filter automatically or use both. Any else seems a bit confusing . . – leora Mar 12 '11 at 18:31
  • @ooo: you can look at all like on two filters: the toolbar and the dialog as the filters only which **exist separately, but will be not applied** till you press "Enter" in the toolbar or till you click on the "Find" button. The both filters will **only saved** in the two controls, but **not applied**. If you apply one filter, for example press enter in the toolbar, the grid will be filled corresponds to the filter, but the contain of the advanced dialog will be not changed. If you click on the "Find" button of the dialog, another filter will applied in grid, but filter toolbar stay unchanged. – Oleg Mar 12 '11 at 18:47
  • @Oleg: I agree with what you are saying and i guess i can live with it as i am display the "real" filter in the caption but i thought it could be a little slicker if the binding of the UI and the actual data filter always forced to be insync – leora Mar 12 '11 at 18:51
  • @ooo: jqGrid can't either combine two filters or to transfer the filter settings from one filter to another. Moreover, the advanced filter can be more complex, so it can not be set in the toolbar filter. I don't recommend you invest too many time in the advanced dialog because it will be replaced with another dialog having other features like filter templates. – Oleg Mar 12 '11 at 18:52
  • @ooo: I can repeat that the thing are different depend on the point of view. If you will see on both filters like two tilter templates you will see no conflict in the jqGrid behavior. You can show two filters and apply only one from there. If you don't want to see both filters at the same time you can use the `toggleToolbar`. See new demo [here](http://www.ok-soft-gmbh.com/jqGrid/MultisearchFilterLocalAtStart2.htm) – Oleg Mar 12 '11 at 19:04
  • @Oleg - i agree that your last demo where the two filter types are toggled back and forth is a pretty good solution to the UI ambiguity. thanks for the last demo . . – leora Mar 12 '11 at 22:35
  • @Oleg - what would make your demo better is if, after you click "Find", it would clear out all text from any toolbarfilter bar. that would make it better when you closed the advanced search gui. – leora Mar 12 '11 at 23:28
  • @ooo: I thought about to clear out all text from any toolbar filter bar, but I find it not good. If one do this the toolbar should clear contain of the Advanced Searching dialog also what you don't want. If you do prefer the clearing of the toolbar behavior you can use `clearToolbar` instead of `toggleToolbar `. – Oleg Mar 13 '11 at 06:43
  • @ooo: During writing the answer on one more [question](http://stackoverflow.com/questions/5429100/when-restoring-jqgrid-via-jqgridimport-search-information-is-incorrect/5430447#5430447) on the close subject I improved the demo which I created for you: see "UPDATED 2" part of my answer. Look also in the code the additional tests inside of `beforeShowSearch` and `onClose` whether the method `toggleToolbar` already defined. It seems be really needed. – Oleg Mar 25 '11 at 09:24