【问题标题】:Custom Search Form in JqGridJqG​​rid 中的自定义搜索表单
【发布时间】:2012-03-06 06:26:55
【问题描述】:

我正在尝试使用 PHP MVC 结构的 JqGrid。 我不想使用 Jq Grid 的搜索功能,而是想要通用关键字搜索。 我在 json 数组中有数据。请让我知道如何使用我的 json 数据集执行搜索。

这个搜索应该在多个列上执行。

这是我的搜索表单

<form name="frmsearch" id="frmsearch">
     <input type="text" id="txtsearch" name="txtsearch"/>
     <a href="javascript:void(0);" onClick="doSearch();">Search</a>
</form>

这是我的网格

$(document).ready(function () {
    jQuery("#agentlist").jqGrid({
        url: "manageagents/getagents/",
        datatype: "json",                
        mtype:"POST",
        jsonReader: {
            root: "rows",
            page: "currpage",
            total: "totalpages",
            records: "totalrecords",
            id: "0",
            cell:"",
            repeatitems: false
        },
        colNames: ['Id','Agent Name', 'Email Address', 'Phone No.1', 'Phone No.2','City', 'State', 'Country'],
        colModel: [ 
                ... ... ...
                  ],
        rowNum:<?php echo $this->config->item('per_page');?>, 
        rowList:<?php echo $this->config->item('nav_page');?>,
        pager: '#plist',
        autowidth: true,
        height: "100%",
        loadonce: true,
        viewrecords: true,
        altRows:true,                
        caption: "",
    }).navGrid('#plist', { edit: false, add: false, del: false, search: true, refresh: false }); ;
});  

【问题讨论】:

    标签: php javascript jquery json jqgrid


    【解决方案1】:

    最简单的方法是将搜索输入字段#txtsearch 中的当前值发送到URL "manageagents/getagents/"。将postData 参数与将发送到服务器的参数名称(如myFilter)之类的属性添加就足够了:

    postData: {
        myFilter: function () { return $("#txtsearch").val(); }
    }
    

    您可以在the answer阅读更多详细信息。

    doSearch 函数内部你可以调用

    jQuery("#agentlist").trigger("reloadGrid", [{page: 1}]);
    

    【讨论】:

      猜你喜欢
      • 2012-12-25
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      相关资源
      最近更新 更多