jqGrid filterToolbar无法正常工作 - ASP.NET

时间:2013-02-13 18:07:14

标签: jqgrid

我正在尝试为jqGrid实现ToolBar搜索/过滤。当我在任何过滤器中输入一些文本并点击输入时没有任何反应 - 不知道我在这里做错了什么。任何帮助表示赞赏:

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" });

2 个答案:

答案 0 :(得分:0)

jqGrid依赖服务器进行过滤功能,如果检查外发帖子操作,您将看到它添加到传递过滤数据的帖子中的额外数据。

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

在我看来,这是一个开始的地方: ASP.NET MVC 2.0 Implementation of searching in jqgrid

从这个例子开始,设置需要花费一些精力,但是从那里你将有一个很好的基础来处理动态过滤。如果您只处理非常基本的过滤,您可能会使用某些组件来破解某些内容,但过去基本要求将使得将时间投入到这个额外选项中是值得的。

答案 1 :(得分:0)

首先尝试添加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" });

})

相关问题