Search in the middle of a column by default in jqGrid with toolbar search

前端 未结 3 1728
轮回少年
轮回少年 2021-01-01 04:21

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 se

相关标签:
3条回答
  • 2021-01-01 04:34
    $(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.

    0 讨论(0)
  • 2021-01-01 04:48
    $("#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.

    0 讨论(0)
  • 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.
    0 讨论(0)
提交回复
热议问题