【问题标题】:jqgrid - how do i persist advanced multiple search on reload of gridjqgrid - 我如何在重新加载网格时坚持高级多重搜索
【发布时间】:2013-03-12 13:54:30
【问题描述】:

我有一个 jqgrid,它会在设定的时间间隔内重新加载并使用多重搜索选项。一切都很好,除了重新加载发生时,我丢失了之前输入的任何过滤/搜索并且所有数据都显示了。

如何在重新加载后保留任何过滤/搜索。代码如下。任何建议表示赞赏:

jQuery(document).ready(function () {
        jQuery("#list").jqGrid({
            datatype: 'json',
            url: 'GetWorkItems.ashx?view=MyActiveItems',
            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', 'TopParentID', 'Title', 'Assigned To', 'Status', 'Priority', 'Classification', 'Affected User', 'Support Group', 'Last Modified'],
            colModel: [
                  { name: 'Icon', index: 'Icon', align: 'right', width: 18, sortable: false, formatter: iconFormatter, search: false },
                  { name: 'Id', index: 'Id', width: 45, sorttype: 'int', firstsortorder: 'desc' },
                  { name: 'TopParentId', index: 'TopParentId', width: 65, align: 'center', sorttype: 'int', hidden: true },
                  { name: 'Title', index: 'Title', width: 180 },
                  { name: 'AssignedUser', index: 'AssignedUser', width: 100, align: 'center' },
                  { name: 'Status', index: 'Status', width: 60, align: 'center' },
                  { name: 'Priority', index: 'Priority', width: 50, align: 'center' },
                  { name: 'Category', index: 'Category', width: 120, align: 'center' },
                  { name: 'AffectedUser', index: 'AffectedUser', width: 100, align: 'center' },
                  { name: 'Tier', index: 'Tier', 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: 'asc',
            viewrecords: true,
            autowidth: true,
            gridview: true,
            loadonce: true,
            ignoreCase: true,
            caption: 'All Active Work Items Assigned To Me',
            onSelectRow: function (id) {
                //doing a redirect here
            }
        });

        $.extend($.jgrid.search, { multipleSearch: true, multipleGroup: true, recreateFilter: true, overlay: 0 });
        jQuery("#list").jqGrid('navGrid', '#pager', { add: false, edit: false, del: false });

        function iconFormatter(cellvalue, options, rowObject) {
            return '<img src="./images/' + cellvalue + '" alt="workitem" />';
        };

        var interval = parseInt($("#<%=hidRefreshInterval.ClientID %>").val());
        window.setTimeout(refreshGrid, interval);

        function refreshGrid() {
            jQuery("#list").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
            window.setTimeout(refreshGrid, interval);
        }
    }); 

【问题讨论】:

  • 嗯,我刚刚在我自己的项目上进行了测试并设置了多个搜索参数,然后触发重新加载保留了所有这些设置,默认情况下,网格将所有搜索参数发回控制器。为什么需要multipleSearch?为什么需要在刷新时重置数据类型?
  • 我认为multipleSearch: true 也没有必要。没有这个你应该可以有多个过滤器(我没有亲自设置它)。您可能还想摆脱 jsonReader ,因为我也认为没有必要。周围应该有大量干净的示例供您构建。最终这是否让你走上了正确的道路?
  • 是的,我通过删除数据类型的重置并像这样更改 JSON 阅读器来让它工作: page: function () { return 1; },总计:函数(){返回1; }, 记录:函数 (obj) { if ($.isArray(obj)) { return obj.length; } if ($.isArray(obj.items)) { 返回 obj.items.length; } 返回 0; },
  • 嘿,我不确定下面是否有任何实质性的答案可以作为答案...输入数据类型的重置?
  • 那行得通 :) 谢谢!

标签: jquery jqgrid


【解决方案1】:

我们发现 'setGridParam', { datatype: 'json' }) 是不需要的,所以应该删除。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多