1

I'm looking for a method to set the default value of multiple columns in the filter toolbar with JSON.

I know I can use the defaultvalue option in searchoptions, but I want to be able to set the filter with a json string.

My json string:

    {"groupOp":"AND","rules": [{"field":"PART_AFFILIATION","op":"eq","data":"PART-M"},{"field":"STATUS","op":"eq","data":"Active"}]}
ffffff01
  • 5,068
  • 11
  • 52
  • 61

1 Answers1

5

The default operation used in the jqGrid can be defined in the colModel. You can use sopt property for the searchoptions. The first element of the array define the operation for the column. The defaultSearch option of the filterToolbar method define the default searching operation only for the column which has no searchoptions.sopt.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • But how can I solve this if I got multiple columns and want to load a set of predefined values? – ffffff01 Feb 14 '12 at 12:35
  • @f01: Sorry, but I don't full understand your question. If you want to change `searchoptions.sopt` *after* the grid is created you can use `setColProp` for example. See [the answer](http://stackoverflow.com/a/5544472/315935)) for an example. – Oleg Feb 14 '12 at 12:41
  • I want to be able to load several predefined filter values in my filter toolbar. Here is a json string to show what my input is: {"groupOp":"AND","rules": [{"field":"PART_AFFILIATION","op":"eq","data":"PART-M"},{"field":"STATUS","op":"eq","data":"Active"}]} As you can see I've got two fields I want to update when the grid loads. – ffffff01 Feb 14 '12 at 12:46
  • Do you understand me Oleg, or should I write a more describing post? – ffffff01 Feb 14 '12 at 13:12
  • @f01: Please be careful with the terminology. You asked in the question about setting of `searchoption`. It is not the same as your last question. The answer on your last question you should find in [the answer](http://stackoverflow.com/a/3981986/315935). [Another answer](http://stackoverflow.com/a/6884755/315935) shows how to fill the filter bar. I recommend you also to read [the answer](http://stackoverflow.com/a/8436273/315935) and to test [the demo](http://www.ok-soft-gmbh.com/jqGrid/ColumnChooserAndLocalStorage2_single.htm) which fill filter toolbar from the `localStorage`. – Oleg Feb 14 '12 at 14:36
  • I have tried setting the postdata as you describe, but I can't seem to get it working. Could you provide a code sample where you put values into the postdata option? – ffffff01 Feb 14 '12 at 18:31
  • @f01: Sorry, but I posted you already many links which use definition or modification of `postData` option. The simplest one and the oldest one is [the demo](http://www.ok-soft-gmbh.com/jqGrid/multisearchfilter.htm) from [the answer](http://stackoverflow.com/a/3981986/315935). – Oleg Feb 15 '12 at 11:08
  • The example you are posting are not using a toolbar at all, so I'm a little confused. I dont got a search form like you, just a toolbar at the top of my grid. – ffffff01 Feb 15 '12 at 12:08
  • 1
    @f01: What you need to do consist from two steps: 1) setting `postData.filters` (see the previous demo and examples) 2) fill the filter from `postData.filters` in the fields of the toolbar filter. The function `refreshSerchingToolbar` from [the answer](http://stackoverflow.com/a/6884755/315935) shows how to fill the filter bar with the value from `postData.filters`. [The next demo](http://www.ok-soft-gmbh.com/jqGrid/ColumnChooserAndLocalStorage2_single.htm) described in [the answer](http://stackoverflow.com/a/8436273/315935) shows even more: it saves/restore **the state of grid** incl. toolbar – Oleg Feb 15 '12 at 12:21
  • Thanks Oleg. I have now managed to post the filter to the advanced search form, but the search filter wont populate/refresh with my current settings.. I'll try some things out and get back to you. – ffffff01 Feb 15 '12 at 15:00
  • I have added my code to the first post. Would you be so kind to review it? I cant get the filter to load in the toolbar. – ffffff01 Feb 15 '12 at 19:09
  • @f01: I think that the error is very easy: you used the code from the answer where described how to synchronize advanced searching and the filter toolbar. The problem which you have in the *first* loading of the grid. In the case you call `refreshSearchingToolbar` inside of `loadComplete` *before* the searching toolbar will be created with `filterToolbar`. So you should move the call of `filterToolbar` inside of `loadComplete`, but call it one time. Look at the code from [the answer](http://stackoverflow.com/a/8547852/315935) inside of `loadComplete`. – Oleg Feb 16 '12 at 06:24
  • I just tried to move the call to filtertoolbar inside of loadcomplete and still the same result. The filter is loaded to the form, but not to the toolbar.. loadComplete: function getCurrentFilter() { if (firstLoad) { firstLoad = false; jQuery("#Jqgrid").jqGrid('filterToolbar'); } refreshSearchingToolbar($(this), myDefaultSearch); }, – ffffff01 Feb 17 '12 at 07:03
  • @f01: Probably you use the filter which can't be represented in the filter toolbar? Look at [one more answer](http://stackoverflow.com/a/9310762/315935) which uses the technique. – Oleg Feb 17 '12 at 07:49