设置数据属性时,jqGrid getLocalRow返回false [英] jqGrid getLocalRow returning false when data property is set

查看:458
本文介绍了设置数据属性时,jqGrid getLocalRow返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用getLocalRow和数据属性时遇到问题

Am having issues using getLocalRow along with data property

var $grid;
getGrid = function () {
    $grid = $("list");
    $grid.jqGrid({
        mtype: "POST",
        colNames: [],
        colModel: [
            ....
        ],
        pager: "",
        loadonce: true,
        multiselect: true,
        gridComplete: function () {
           var data = $(this).getDataIDs();
           for(var i=0; i < data.length;i++){
                $(this).setSelection(data[i]); // select all rows by default
           }
        },
        loadComplete: function (data) {

        },
        loadError: function (xhr) {

        }
    });
    return $grid;
};

基于2种情况,有两种方法填充网格.
在方案1中,只是访问服务器URL,然后将数据作为JSON返回并填充到网格中.使用此选项,当我遍历选定的行并执行getLocalRow时,将获得所需的o/p.

There are two ways am populating the grid based on 2 scenarios.
In scenario 1, am just hitting server url and returning the data as JSON and populating in the grid. Using this option, when I iterate thru the selected rows and perform getLocalRow am getting the required o/p.

在场景2中,我构造了一个数据对象并将其传递到同一网格.当我在此上下文中迭代并使用getLocalRow时,在这里发生的问题是所有选定行(而不是行数据)都为false,但与getRowData可以很好地工作.

And in scenario 2, I construct a data object and pass it to the same grid. The problem occurs here when I iterate and use getLocalRow in this context am getting false for all the selected rows instead of the row data but works fine with getRowData.

场景1:

$grid.jqGrid("clearGridData");
$grid.jqGrid("setGridParam", {url: '..', datatype: "json"}).trigger("reloadGrid");

场景2:

$grid.jqGrid("clearGridData");
$grid("setGridParam", { data: MyOWNobject}).trigger("reloadGrid");        

访问getLocalRow:

Accessing getLocalRow :

var sel=[];
for (i = 0; i < $grid.jqGrid("getGridParam").selarrrow.length; i++) {
    sel.push($grid.jqGrid("getLocalRow", $grid.jqGrid("getGridParam").selarrrow[i]));
}

推荐答案

问题在于网格的填充.网格的每一行都必须具有唯一的id.如果您的数据已经有一些包含唯一数据的列,则可以在该列中使用key: true来通知jqGrid使用该列中的值作为rowid.

The problem is in the filling of the grid. Every row of the grid have to get unique id. If your data already have some column with unique data then one can use key: true in the column to inform jqGrid to use the value from the column as the rowid.

我上次使用数据始终测试了免费的jqGrid,该数据在具有key: true属性的每一列中都包含id属性,该列的值希望用作行ID.如果您遵循规则,那么您报告的问题将不存在.请参阅演示 http://jsfiddle.net/OlegKi/y9KHY/92/,该演示使用了代码

I tested last time free jqGrid always with the data, which contains either id property in every column of have key: true property for a column which values one want use as the rowid. If you would follow the rule then the problem which you reports will not exist. See the demo http://jsfiddle.net/OlegKi/y9KHY/92/ which uses the code

$("#submit1").click(function () {
    var $grid = $("#gGrid");
    var grps = [
            { Name : "A",  Group : "11" },
            { Name : "B" , Group : "1122" }
        ];
    $grid.jqGrid({
        data: grps,
        colModel: [
            { name: 'Name', key: true },
            { name: 'Group' }
        ],
        cmTemplate: {width: 200},
        rownumbers: true,
        multiselect: true,
        gridComplete: function () {
            $("#cb_" + this.id).click();
        }
    });
});

$("#submit2").click(function () {
    var $grid = $("#gGrid"), p = $grid.jqGrid("getGridParam"), i;

    for (i = 0; i < p.selarrrow.length; i++) {
        alert("Data  > " + JSON.stringify($grid.jqGrid("getLocalRow", p.selarrrow[i])));
    }
});

演示 http://jsfiddle.net/OlegKi/y9KHY/93/使用输入数据中的id属性.

The demo http://jsfiddle.net/OlegKi/y9KHY/93/ uses id property in input data.

尽管如此,通常允许在未指定rowid的情况下使用不完整的输入数据.因此,免费jqGrid的上述行为是一个错误.这些错误已在GitHub上免费jqGrid的代码中修复.您可以在演示 http://jsfiddle.net/OlegKi/y9KHY/94/,直接使用GitHub中的代码.我计划很快发布下一个版本.

Nevertheless, the usage of not full input data, without specifying rowid is allowed in general. Thus the described above behavior of free jqGrid is a bug. The bugs is fixed already in the code of free jqGrid on GitHub. You can verify it in the demo http://jsfiddle.net/OlegKi/y9KHY/94/, which uses the code directly from GitHub. I plan publish the next version soon.

这篇关于设置数据属性时,jqGrid getLocalRow返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆