无法使用新的json数据重新加载JQGrid

时间:2016-01-17 17:33:08

标签: jquery json asp.net-mvc jqgrid

我无法使用从控制器接收的新json数据重新加载JQGrid。在下面显示的代码中,我在成功接收数据并将其传递给另一个方法后显示警报。但是我无法刷新数据。有关如何解决此问题的任何建议吗?

代码: -

$.ajax({
    type: 'post',
    url: '/TodoList/searchdata',
    traditional: true,
    dataType:"json",
    data: d,
    success: function (data) {
        alert(JSON.stringify(data));                 
        callme(data);
    }
})

给我打电话: -

function callme(newone1) {
    $grid.jqGrid('clearGridData');
    $grid.jqGrid({
        //autowidth: true,
        caption: "Evaluated URLs",
        colNames: ["AccountName", "BU", "Salesop", "Isdormant"],
        colModel: [
            { name: "AccountName", align: "center", title: false, width: 400, resizable: false, sortable: false },
            { name: "BU", width: 125 },
            { name: "Salesop", align: "center", width: 125, sorttype: "date" },
            { name: "Isdormant", align: "center", width: 125, sorttype: "date" }
        ],
        data: newone1,
        datatype: 'json',
        emptyrecords: "0 records found",
        multiselect: true,
        localReader: {
            page: function (obj) {
                return (obj.page === 0 || obj.page === undefined) ? "0" : obj.page;
            }
        },
        loadComplete: function () {
            var ts = this;
            if (ts.p.reccount === 0) {
                $(this).hide();
                emptyMsgDiv.show();
            } else {
                $(this).show();
                emptyMsgDiv.hide();
            }
        },
        height: "auto",
        sortname: "created",
        toppager: true,
        pager: "#url-pager",
        viewrecords: true
    }).trigger("reloadGrid");
    //$grid.jqGrid('setGridParam',
    //{    
    //    datatype: 'json',
    //    data: newone1
    //}).trigger("reloadGrid",[{page:1}]);
}

Json data received is showing in an alert

1 个答案:

答案 0 :(得分:1)

您可以使用新数据重新加载jqgrid。在ajax成功时,请执行以下操作。

var $grid=$('#your_grid_id');
$grid.jqGrid('setGridParam', { datatype: 'local', data: data }).trigger("reloadGrid");

DEMO