0

I currently have this jqGrid column search option defined;

colDefs.Append(",stype: 'select', searchoptions: { sopt: ['eq', 'ne'], value: ':All;99:Yes;1:No'}");

So it correctly filters to value 99 for search option 'Yes' and to value 1 for 'No'.

How can I make it filter to anything other than 99 (i.e. NOT 99) for 'No' instead of just 1?

I tried a few guesses like ...;!99:No'}" but they just error.

Users are not able or required to choose between Equals/Not equals or any other filtering option. They only get to select from the three fixed options, 'All', 'Yes' or 'No'.

Currently 'All' shows all records, 'Yes' shows only records with value '99' (data is string), 'No' shows only records with value '1'.

What I am aiming for 'All' should show all records, 'Yes' should show only records with value '99' and 'No' should show all records where value is NOT '99'. Can I define 'searchoptions' to do this?

Cell datatype is String.

FilterToolbar defined by

   $('#' + this.instance + '_GridContainer_grid').jqGrid('filterToolbar', {
    stringResult: true,
    defaultSearch: 'cn'
});

Filtering is local, not server.

Thanks!

  • Sorry, but it's absolutely unclear what you do. The statement `colDefs.Append(...)` could be wrong or correct depend on the context. jqGrid is pure **JavaScript** product. You should include JavaScript code to prevent misunderstanding. You write "I make it filter". What you mean? Do you use Searching Dialog, filterToolbar or you set the filter inside of `postData` directly? Which `datatype` you use? Do you filter *locally* or on the server? Which version of jqGrid you use and from which fork of jqGrid (free jqGrid, commercial Guriddo jqGrid JS or an old jqGrid in version <=4.7)? – Oleg Jul 27 '16 at 09:30
  • The colDefs code is correct; this is coming from a live system with many working grids. Sorry about the filter confusion; in this system the search options define column filtering so there is (in this case) an 'All, Yes, No' drop-down menu in row one underneath the header line. Selecting from the drop-down filters the results based on the search criteria defined in the searchoptions code. I inherited this so don't shoot me! I am hoping to get some insight into the workings of 'sopt' and (I think) how to define separate 'ne' and 'eq' rules for a column. Version is 4.6.0. – AnotherFineMess Jul 27 '16 at 09:45
  • **Which `datatype` you use? Do you filter locally or on the server?** It's difficult to follow you if you don't post the corresponding JavaScript code. I try to explain shortly. It seems that you use `filterToolbar` method to create [the filter toolbar](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching). **Which options of `filterToolbar` you use?** For example `searchOperators: true` option allows the user to select the filter operation (not equal). Do you need to set the filter *by your program* or the user should have the possibility to choose `ne` operation? – Oleg Jul 27 '16 at 10:19
  • I've updated the question. Thanks very much for your help Oleg. – AnotherFineMess Jul 27 '16 at 10:49
  • You are welcome! I wrote you about `searchOperators: true` option of `filterToolbar`. If I correctly understand you then you should use `.jqGrid('filterToolbar', {searchOperators: true, stringResult: true, defaultSearch: 'cn'})`. See [the example](http://www.ok-soft-gmbh.com/jqGrid/OK/formEditOnDoubleClick-jqueryui-fa2.htm). – Oleg Jul 27 '16 at 10:59
  • About searchOperators the documentation says, 'When set to true allows the user to select operations when searching'. I do not want the user to have options. I just want the 'No' filter to show every value except 99 (with 'Yes' showing only 99). – AnotherFineMess Jul 27 '16 at 11:25
  • 1
    I still can't follow you. If you don't use `searchOperators: true` then the *second* operation from `sopt` will be never used by filter toolbar (the *first* operation will be always applied). If you want to apply `'ne'` instead of `'eq'` if the user choose some option in the filter toolbar for the column then you should use `sopt: ['ne']` or `sopt: ['ne', 'eq']` instead of `sopt: ['eq', 'ne']` – Oleg Jul 27 '16 at 11:51
  • Please correct the text of your question so that it could be understood more clear. For example you wrote "Users cannot select between Equals/Not equals. They only get the option of 'All'/'Yes'/'No'.". I read it as the description of your current problem and the providing an option where the user *could* select between Equals/Not equals could be the solution, but your last comment shows that it's not what you want. The statement "How can I make it filter to anything other than 99 (i.e. NOT 99) for 'No' instead of just 1?" can be interpreted in many ways too (setting the filter by program etc) – Oleg Jul 27 '16 at 11:59
  • Ok, I appreciate the difficulty better now. I did not understand what sopt is for until you described that without searchoperators: true only the first would ever be used. Clearly the original developer didn't either as searchoperators is never true and so sopt should only ever have one value, ['eq']. Thanks for making that clear! – AnotherFineMess Jul 27 '16 at 12:32
  • You are welcome! Very old version of jqGrid didn't support `searchOperators: true`. The options `sopt` will be used not only by the filter toolbar. If you call `navGrid`, it adds icons in the filter toolbar, inclusive Search icon (one can call [searchGrid](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:singe_searching#calling_conventions) directly). One can use `multipleSearch: true, multipleGroup: true` option to create more advanced searching rules. The searching dialog can be used *together* with filter toolobar and the `searchoptions` are common. Dialog allows to choose the operations. – Oleg Jul 27 '16 at 13:00

1 Answers1

0

If you filterToolbar without searchOperators: true option then the first searching operation from sopt will be used. You can change sopt: ['eq', 'ne'] to sopt: ['ne'] or to sopt: ['ne', 'eq'] to apply "not equal" operation in the column.

The reason of such settings is the following. searchoptions will be used by both filter toolbar and searching dialog (see here and here). If no searchoptions.sopt exist in the column then the searching operation defaultSearch (used as the option of filterToolbar) be applied for all columns. If you would use select with values 1,2,...11,12,13,... then searching for the value '1' will shows the rows with the values 1, 11, 12, 13, ... because all the values contains substring '1'. Thus one defines searchoptions.sopt typically always if one uses stype: 'select'.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I think I understand about defining sopt ['eq'] to match specific [value] now. But within the same filterToolbar dropdown list I want an option to filter on 'everything except [value]'. Is this even possible, maybe with a completely different mechanism than searchOperators? – AnotherFineMess Jul 27 '16 at 15:00
  • @AnotherFineMess: I don't understand the problem. Try `{ sopt: ['ne', 'eq'], value: ':All;99:not 99;1:Not 1'}"`. You can implement *any custom operation* by upgrading to [free jqGrid](https://github.com/free-jqgrid/jqGrid) 4.13.4, the fork of jqGrid, which I develop. See [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/Custom-filtering-searching-Operation), [the answer](http://stackoverflow.com/a/28615923/315935), [this one](http://stackoverflow.com/a/29415927/315935), [this one](http://stackoverflow.com/a/29676941/315935) or [this one](http://stackoverflow.com/a/37262509/315935). – Oleg Jul 27 '16 at 15:14