jqGrid filterToolbar不工作-ASP.NET

jqGrid filterToolbar不工作-ASP.NET,jqgrid,Jqgrid,我正在尝试为jqGrid实现工具栏搜索/过滤。当我在任何一个过滤器中输入一些文本并按enter键时,什么也没有发生——我不确定我在这里做错了什么。感谢您的帮助: jQuery("#list").jqGrid({ datatype: 'json', url: 'GetIncidents.ashx?view=MyIncidents', height: "100%", scrollOffset: 0,

我正在尝试为jqGrid实现工具栏搜索/过滤。当我在任何一个过滤器中输入一些文本并按enter键时,什么也没有发生——我不确定我在这里做错了什么。感谢您的帮助:

jQuery("#list").jqGrid({
            datatype: 'json',
            url: 'GetIncidents.ashx?view=MyIncidents',
            height: "100%",
            scrollOffset: 0,
            jsonReader: {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: false,
                cell: "cell",
                id: "ID",
                userdata: "userdata",
                subgrid: {
                    root: "rows",
                    repeatitems: true,
                    cell: "cell"
                }
            },
            colNames: ['ID', 'Title', 'Assigned To', 'Status', 'Priority', 'Classification', 'Affected User', 'Support Group', 'Last Modified'],
            colModel: [
                  { name: 'ID', index: 'ID', width: 40, sorttype: 'int', firstsortorder: 'desc' },
                  { name: 'Title', index: 'Title', width: 180 },
                  { name: 'AssignedUser', index: 'AssignedUser', width: 100, align: 'center' },
                  { name: 'Status', index: 'Status', width: 50, align: 'center' },
                  { name: 'Priority', index: 'Priority', width: 50, align: 'center' },
                  { name: 'Classification', index: 'Classification', width: 150, align: 'center' },
                  { name: 'AffectedUser', index: 'AffectedUser', width: 100, align: 'center' },
                  { name: 'TierQueue', index: 'TierQueue', width: 100, align: 'center' },
                  { name: 'LastModified', index: 'LastModified', width: 120, align: 'center', formatter: 'date', formatoptions: { srcformat: 'Y-m-d H:i:s0', newformat: 'm/d/Y h:i A'}}],
            pager: '#pager',
            rowNum: 15,
            width: 980,                
            sortname: 'ID',
            sortorder: 'desc',
            viewrecords: true,
            autowidth: true,
            gridview: true,
            ignoreCase: true,
            caption: 'All Open Incidents Assigned To Me',
            onSelectRow: function (id) { window.location = 'ViewIncident.aspx?id=' + id; }
        });

        jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });

jqGrid依赖服务器提供过滤功能,如果检查传出的post操作,您将看到它添加到post的额外数据传递过滤数据

因此,您的过滤将在服务器上完成,然后过滤的数据集将被排序/分页,等等,然后传递回jqGrid

在我看来,这是一个开始:


从这个例子中,需要花费一些精力来设置,但从那里你将有一个很好的基础来处理动态过滤。如果您只处理非常基本的过滤,那么您可能可以使用一些组件来删除某些内容,但远远超出了基本要求,因此值得在这个额外选项上投入时间

首先尝试添加document.ready函数,让浏览器在启动网格之前加载,然后添加loadonce:true

然后试着运行它,它应该会工作

这是密码

 JQuery(document).ready(function(){
 jQuery("#list").jqGrid({
        datatype: 'json',
        url: 'GetIncidents.ashx?view=MyIncidents',
        height: "100%",
        scrollOffset: 0,
        jsonReader: {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            cell: "cell",
            id: "ID",
            userdata: "userdata",
            subgrid: {
                root: "rows",
                repeatitems: true,
                cell: "cell"
            }
        },
        colNames: ['ID', 'Title', 'Assigned To', 'Status', 'Priority', 'Classification', 'Affected User', 'Support Group', 'Last Modified'],
        colModel: [
              { name: 'ID', index: 'ID', width: 40, sorttype: 'int', firstsortorder: 'desc' },
              { name: 'Title', index: 'Title', width: 180 },
              { name: 'AssignedUser', index: 'AssignedUser', width: 100, align: 'center' },
              { name: 'Status', index: 'Status', width: 50, align: 'center' },
              { name: 'Priority', index: 'Priority', width: 50, align: 'center' },
              { name: 'Classification', index: 'Classification', width: 150, align: 'center' },
              { name: 'AffectedUser', index: 'AffectedUser', width: 100, align: 'center' },
              { name: 'TierQueue', index: 'TierQueue', width: 100, align: 'center' },
              { name: 'LastModified', index: 'LastModified', width: 120, align: 'center', formatter: 'date', formatoptions: { srcformat: 'Y-m-d H:i:s0', newformat: 'm/d/Y h:i A'}}],
        pager: '#pager',
        rowNum: 15,
        width: 980,                
        sortname: 'ID',
        sortorder: 'desc',
        viewrecords: true,
        autowidth: true,
        gridview: true,
        ignoreCase: true,
        loadonce:true,  //**you need to add this**
        caption: 'All Open Incidents Assigned To Me',
        onSelectRow: function (id) { window.location = 'ViewIncident.aspx?id=' + id; }
    });

    jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });
})