jqGrid不会刷新新数据

时间:2015-04-29 13:15:30

标签: jquery jqgrid

我从服务器获取json数据,传入一个页码n,它应该得到第n行100行。加载一次后,按下“下一页”按钮,它似乎正确地获取新数据(我在刷新时输出新数据中的第一个对象),但它不会在我的网格中填充该数据。 / p>

<div>
    <button id="refreshJobsButton">Refresh Jobs</button>
    <button id="nextPageJobsButton">Next page</button>
    <table id="JobTable"><tr><td/></tr></table>
    <div id="JobPager" class="ui-widget"></div>
</div>
$(document).ready(function() {
    var page = 0;
$('#nextPageJobsButton').button({
            icons: {
                primary: "ui-icon ui-icon-arrowrefresh-1-s"
            }
    }).click(function(){
    page = page + 1;
$("#JobTable").jqGrid('GridUnload');
        refreshJob(page);
        });
};
        function refreshJob(page) {
            var $source = "ajax/refreshJob?page=" + page;

        $.ajax({
            url: $source,
            dataType: "json",
            success: populateJobs,
            error: handleAjaxError
        });
    }

        function populateJobs(jobs) {
    k = Object.keys(jobs)[0];
    l = Object.keys(jobs[k])[0];
    alert ("First job in list is " + jobs[k][l]); //Outputs correct job of that page

        $(function() {
            var grid = $('#JobTable');
            $('#JobTable').jqGrid({
                datatype: 'jsonstring',
                editurl: 'ajax/modifyJob',
                mtype: 'POST',
                loadonce: false,
                datastr: jobs,
                height: 600,
                autowidth: true,
                forceFit: true,
                gridview: true,
                viewrecords: true,
                multiselect: true,
                sortable: false,
                toppager: true,
                treeGrid: true,
                treeGridModel: 'adjacency',
                treedatatype: 'POST',
                ExpandColumn: 'Job',
                ExpandColClick: true,
                colNames: [
                    "Id (hidden)",
                    "Job Type (hidden)"
                ],
                colModel: [{
                    name: 'id',
                    index: 'id',
                    editable: true,
                    edittype: 'text',
                    key: true
                }, {
                    name: 'jobType',
                    index: 'jobType',
                    editable: true,
                    edittype: 'text'
                }],
                jsonReader: {
                    repeatitems: false,
                    root: function(obj) {
                        return obj;
                    },
                    page: function() {
                        return 1;
                    },
                    total: function() {
                        return 1;
                    },
                    records: function(obj) {
                        return obj.length;
                    }
                }
            });

有人可以告知错误吗?

0 个答案:

没有答案