【问题标题】:Jqgrid doesn't reload when using pager使用分页器时 Jqgrid 不会重新加载
【发布时间】:2012-12-18 07:01:37
【问题描述】:

我希望我的 jqgrid 以编程方式移动带有重新加载数据的下一页。例如:每 5 秒换页并获得刷新数据。 ---> 数据类型:'json'

我阅读并尝试,尝试,尝试了一切,但到目前为止还没有运气。请帮忙..

    <script>
       function fill() {
        jQuery("#jqGrid").jqGrid({
            url: '@Url.Content("~/Handler/GetAjaxGridData")',
            datatype: 'json',
            height: 'auto',
            altRows: true,
            loadonce:true,
            pager: '#pager',
            rowNum: 3,
            colNames: ['birim_adi', 'durum'],
            colModel: [
                     { name: 'cell.birim_adi', index: 'birim_adi' },
                      { name: 'cell.durum', index: 'durum' }
            ],
            jsonReader: {
                repeatitems: false,
                root: function (obj) { return obj.rows; },
                page: function (obj) { return 1; },
                total: function (obj) { return 1; },
                records: function (obj) { return obj.rows.length; }
            },
            loadComplete: function (data) {
                var total_pages = $("#sp_1_pager").text(); // total pages
                $('#hdn_total_pages').val(total_pages);
            },
            ajaxGridOptions: { cache: false }
        });
    }
    function loop() {
        var i = 1;
        setInterval(function () {
            var total_pages = $('#hdn_total_pages').val();
            $("#jqGrid").setGridParam({
                datatype: 'json', // <--When I delete it goes to another page, but the page does not refresh.
                page: i,
            }).trigger('reloadGrid');
            i++;
            if (i > total_pages) { i = 1; }
        }, 5000);
    }
       </script>
       <script>
        $(function () {
        fill();
        loop();
       });
       </script>
<table id="jqGrid"></table>
<div id="pager"></div>
<input type="hidden" id="hdn_total_pages" value="1" />

然后我的 json 是这样的:

   {
"total": 1,
"page": 1,
"records": 6,
"rows": [
    {
        "id": 1,
        "cell": {
            "birim_adi": "a",
            "durum": "test"
        }
    },
    {
        "id": 2,
        "cell": {
            "birim_adi": "b",
            "durum": "test1"
        }
    },
    {
        "id": 3,
        "cell": {
            "birim_adi": "c",
            "durum": "test3"
        }
    },
    {
        "id": 4,
        "cell": {
            "birim_adi": "d",
            "durum": "test4"
        }
    }
]
   }

【问题讨论】:

    标签: json jqgrid refresh pager


    【解决方案1】:

    jsonReader 正在为页面返回硬编码值“1”。看起来您的数据符合 jqGrid 将自动使用的结构。您可以尝试完全删除 jsonReader 部分并试一试。

    如果这不起作用(或者您的数据名称与 jqGrid 预期的不同),您将需要查看修复 jsonReader 以返回正确的值。

    看看这个blog entry 关于自定义 jsonReader 以使用不同的数据格式。它可能会帮助您解决页面卡住的问题。 (完全披露:我是作者。)

    【讨论】:

      猜你喜欢
      • 2011-10-27
      • 2023-03-30
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      • 1970-01-01
      相关资源
      最近更新 更多