0

i want my jqgrid programmatically move next page with reloaded data. for example: every 5 seconds change page and get refreshed data. ---> datatype: 'json' <--- is in loop() function. brings reloaded page, but it does not pass the next page. stuck on the first page. if i delete it goes the next page, but the page doesn't refresh.

i read and tried, tried, tried everything but no luck as of yet. Please help..

    <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" />

and then my json like this:

   {
"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"
        }
    }
]
   }
blackraist
  • 183
  • 1
  • 6
  • 17

1 Answers1

0

The jsonReader is returning a hard-coded value of '1' for page. It looks like your data conforms to the structure jqGrid will work with automatically. You might just try deleting the jsonReader section entirely and give it a shot.

If that's not working (or your data has different names than jqGrid is expecting) you will need to look at fixing jsonReader to return proper values.

Take a look at this blog entry about customizing the jsonReader to work with different data formats. It might help you resolve the page getting stuck. (Full disclosure: I'm the author.)

Erik Noren
  • 4,279
  • 1
  • 23
  • 29