【问题标题】:Jqgrid is not updating with new dataJqgrid 没有用新数据更新
【发布时间】:2016-01-18 04:59:36
【问题描述】:

我有 jqgrid 实现,但无法在其中加载数据。我附上代码,请告诉我。我正在成功地从控制器中检索数据,但无法使用新数据重新加载 jqgrid。

$("#btn1").on("click", function() {
    alert(j + " " + k);
    var d = { 'firstField': i, 'secondField': j, 'thirdField': k }
    $.ajax({
        type: 'post',
        url: '/TodoList/searchdata',
        traditional: true,
        dataType: "json",
        data: d,
        success: function(data) {
            callme(data);
        }
    })

});

function callme(newone1) {
    var my = JSON.stringify(newone1.rows);
    alert(my);
    /*
        Json showing in this alert is 
        [{"accntname":"BSNL","BU":"BCS","salesop":50000,"isdormant":true},
         {"accntname":"TATA","BU":"HPSD","salesop":50000,"isdormant":false}]
        */

    $grid.jqGrid('clearGridData');
    $grid.jqGrid('setGridParam', {
        datatype: 'local',
        data: my
    }).trigger("reloadGrid");
}

我正在尝试用新数据重新加载的 Jqgrid:

var mydata = [];
$grid.jqGrid({
    datatype: "local",
    data: mydata,
    colModel: [
        { name: "accntname", 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" }
    ],
    caption: "Viz Test",
    pager: '#pager',
    search: true,
    multiselect: true
});

【问题讨论】:

  • 那么也许你应该考虑接受这个答案。

标签: jquery json asp.net-mvc jqgrid


【解决方案1】:

您收到的数据是 json,这是 Jqgrid 所期望的,因为您不应该对数据进行字符串化。修改函数为

function callme(newone1) {
    $grid.jqGrid('clearGridData');
    $grid.jqGrid('setGridParam', {
      datatype: 'local',
      data: newone1.rows // modify this
    }).trigger("reloadGrid");
}

旁注:traditional: true ajax 选项不是必需的(您没有向控制器发送数组)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    • 2013-10-03
    • 1970-01-01
    • 2011-11-04
    相关资源
    最近更新 更多