Search in the middle of a column by default in jqG

2019-02-11 02:36发布

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%';

3条回答
一夜七次
2楼-- · 2019-02-11 03:07

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.
查看更多
▲ chillily
3楼-- · 2019-02-11 03:13
$(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.

查看更多
贼婆χ
4楼-- · 2019-02-11 03:15
$("#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.

查看更多
登录 后发表回答