4

After reading the jqGrid wiki (and taking example from: Case insensitive search in jqGrid including hidden fields), I cannot find what I want to do.

Is there any search option to enable a search anywhere in a column (automatically wildcarded).

If the column contains "Apple Iphone" I would be able to find it by using the search "iphone".

The SQL equivalent would be select * from table where lower(columnX) like '%iphone%';

Community
  • 1
  • 1
рüффп
  • 5,172
  • 34
  • 67
  • 113
  • 1
    Could you include in your question more information? For example: do you use local searching (`datatype:local` or `loadonce:true`) or you implement all on the server? Which searching you use: [Toolbar searching](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching), [Single Value searching](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:singe_searching) or [Advanced searching](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:advanced_searching)? Do you need to implement searching on hidden column? – Oleg Mar 31 '11 at 12:57
  • 1
    Hello, I use the toolbar search, without hidden fields. I implement all in the html part; I do no have any web-server as I do a simple-to-use xml-to-html formatting. If I understand properly, there is not a simple parameter to set but a function to implement from scratch. Thanks for your support. – рüффп Apr 04 '11 at 11:14

3 Answers3

17

Since you use toolbar searching the solution of your problem seems to be simple. You should:

  1. include ignoreCase:true to the jqGrid parameters
  2. include defaultSearch:'cn' option to the call of filterToolbar. For example: $("#list").jqGrid('filterToolbar', {defaultSearch:'cn'}).
  3. If you use any select elements in the searching toolbar (stype:'select') you should include in the list of searchoptions the sopt options which begin with 'eq': stype:'select', searchoptions: {sopt:['eq','ne']} for example.
Jess Stone
  • 677
  • 8
  • 21
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • the missing parameter was your second point. Thanks for the clarification and solution. – рüффп Apr 06 '11 at 14:16
  • I am using datatype: local. $("#myGrid").jqGrid('filterToolbar', {defaultSearch:'cn'}) doesnt work. Does it work only for json? – Rustin Cohle Jul 02 '16 at 12:04
  • 1
    @RustinCohle: It should work. If it doesn't work in your code then you have some another problem. You should post more full code which you use or better the demo, which reproduces your problem. – Oleg Jul 02 '16 at 12:25
  • @Oleg thanks. It works, my bad. I have searched through various forms. For some reason I cant post a question myself. I have two issues: 1: with local datatype, while searching on a date column with filter toolbar, jqgrid takes Y-m-d format default, my format is m/d/Y, jqgrid cant recognize it. 2: I have used a custom formatter to change a boolean column to Yes/No, now on searching via filter toolbar, it searches for database value instead of formatted text. Please help. Thanks. – Rustin Cohle Jul 02 '16 at 12:52
  • I am using Tony's 4.6.0 fork – Rustin Cohle Jul 02 '16 at 12:52
  • 1
    @RustinCohle: It's important to distinguish the format of *input* data (in the input `data` parameter) from the format of *displayed* data. One uses typically `formatter` and `formatoptions` to customize the format of *displayed* data. It's important to post the definition of `colModel` for the column with the date and to post an example of input data (which you use in the input `data` parameter). Which options of `filterToolbar` you use? In case of custom formatter one should don't forget to define `unformat` function too and to define `searchoptions` with `sopt`, which starts from `"eq"`. – Oleg Jul 02 '16 at 15:45
  • @Oleg Thanks. For date Column I am using `newformat` as m\d\Y and `formatter` as date to customize displayed data. and `sorttype` as date. I am sorry, I am unable to post a sample. In filter toolbar only two options `searchonenter: false` and default filter as `cn`. Now filter toolbar searches only Y-m-d format. – Rustin Cohle Jul 03 '16 at 16:42
  • 1
    @RustinCohle: You should include `searchoptions: { sopt: ["eq", ...] }` because you don't want to use `"cn"` as the search operation in the column. Moreover you should not explain what you use, but just include exact column definition. It's better to create the demo on https://jsfiddle.net/ – Oleg Jul 03 '16 at 21:09
  • @Oleg Thanks. Here in this http://jsfiddle.net/ejnrtocw/63/ on searching the date column, I am using `cn`, its still looking for Y-m-d though. backslashes are not recognized. – Rustin Cohle Jul 04 '16 at 07:09
  • @Oleg I am looking for both cn and eq in searching date. – Rustin Cohle Jul 04 '16 at 07:20
  • @RustinCohle: Sorry, but I wrote you multiple times about the importance of the usage of `searchoptions: { sopt: ["eq", ...] }`. Simple adding of `searchoptions: { sopt: ["eq"] }` in your demo solves the problem. See http://jsfiddle.net/ejnrtocw/64/ – Oleg Jul 04 '16 at 07:41
  • @Oleg Thankyou. I know. but I want the 'contains' search as well. Suppose user want to search by year alone. if he types 2016, it should list all 2016 year dates. I want both eq and cn. – Rustin Cohle Jul 04 '16 at 09:39
  • @RustinCohle: You can't do this in the old jqGrid 4.6.0. The old version have *fixed code*, which generates filtering statements. The code for Date type and 'contains' operation is not correct like you can see yourself. I implemented **custom filtering** in free jqGrid fork. See [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/Custom-filtering-searching-Operation) for more details. [The demo](http://www.ok-soft-gmbh.com/jqGrid/OK/DatetimeSearch1.htm) created for [the issue](https://github.com/free-jqgrid/jqGrid/issues/50) provides the solution, which you can easy modify to youth. – Oleg Jul 04 '16 at 10:00
1
$("#list").jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch : "cn"});

In the above example the **defaultSearch : "cn"** is used to search using any substring of item you want to search. Removing defaultSearch : "cn" starts search beginning with the substring.

Jess Stone
  • 677
  • 8
  • 21
1
$(document).ready(function() {
  colNamesData = [ 'Description']

  {name:'description',index:'description', width:130, sorttype:"text", search:true, editable:true, edittype:"textarea", editoptions: {rows:"5",cols:"25",maxlength:"255"}, stype:'text', searchoptions:{sopt:['cn', 'nc', 'bw', 'bn', 'ew', 'en']}},

$("#description_table").jqGrid({
      datatype: "local", 
      height: "auto",
      autowidth: true,
      ignoreCase: true,
      colNames: colNamesData, 
      colModel: colModelHash,
      pager: '#pager',
      rowNum:10,
      rowList:[10,25,50,100],
      sortname: 'date',
      sortorder: 'desc',
      viewrecords: true,
      editurl:"/url_name.json", 
      caption: 'Description'
 data:<%= raw @jqgrid_table.to_json %>
   });

   jQuery("#description_table").jqGrid('navGrid','#pager',{del:false,add:true,edit:false},{}, {modal: true,afterSubmit:processAddEdit,recreateForm:true, afterComplete:reloadJqGrid}, {modal: true}, {multipleSearch:true});  

Now if your text contains "here i go" and if you search "go", it will surely search, it works for me.

Give a try and reply if it doesn't.

рüффп
  • 5,172
  • 34
  • 67
  • 113
Bijendra
  • 9,467
  • 8
  • 39
  • 66