jqgrid: getCell 总是 returns 错误

jqgrid: getCell always returns false

我目前正在从事一个项目,该项目涉及从 jqgrid 的特定列中获取值。有人告诉我你应该为此使用 'getCell',但它没有给我一个值,而是总是 returns false。谁能帮我解决这个问题?我渲染 JqGrid 的代码如下:

RenderGrid: function () {
            var $deft = $("#MyGrid");
            $("#MyGrid").jqGrid({
                datatype: "local",
                editurl: "<%=Session("BaseUri")%>" + '/path/to/irrelevant/helper/page',
                colNames: ['Actions', 'ButtonId', 'DefectCode', 'Name', ],
                colModel: [
                    { name: 'act', index: 'act', width: 100, sortable: false },
                    { name: 'ButtonId', index: 'ButtonId', editable: false, width:50 },
                    { name: 'DefectCode', index: 'DefectCode', editable: true, width: 50 },
                    { name: 'Name', index: 'Name', sortable: false, width: 200, editable: true }



                ],
                pager: '#pMyGrid',
                caption: "McGriddles",
                multiselect: false,
                loadonce: false,
                rowNum: 10,
                viewrecords: true,
                sortorder: "desc",
                width: new Number(300),
                gridview: true,
                height: "100%",
                data: ButtonLibrary,

                ondblClickRow: function (id) {
                    if (id && id !== lastSel) {
                        jQuery("#MyGrid").restoreRow(lastSel);
                        lastSel = id;
                    }
                    jQuery("#MyGrid").editRow(id, true);

                },
                gridComplete: function () {

                    var ids = jQuery("#MyGrid").jqGrid('getDataIDs');
                    for (var i = 0; i < ids.length; i++) {
                        var cl = ids[i];
                        be = "<input style='height:22px;width:20px;' type='button' value='E' onclick=\"jQuery('#MyGrid').editRow('" + cl + "');\"  />";
                        se = "<input style='height:22px;width:20px;' type='button' value='S' onclick=\"jQuery('#MyGrid').saveRow('" + cl + "');\"  />";
                        var ButtonId = $('#MyGrid').jqGrid('getCell', ids[i], 'ButtonId');


//------------->         console.log(ButtonId); //always returns false
                            GBDelete = "<input style='height:22px;width:20px;' type='button' value='X' onclick=\"DeleteRowData('" + cl + "');\"  />";
                        jQuery("#MyGrid").jqGrid('setRowData', ids[i], { act: be + se + GBDelete });
                    }
                }

            });


        },


        };

getCell return false 两种情况: 1.如果在colModel中找不到列名或者 2.行号找不到

为此,最好从响应中获取一列或数据作为 ID。

在您的情况下使用本地数据时,最好在 colModel 数组中设置 key:true 以便正确工作。

此外,我的建议是有一个列作为 id(确保它具有唯一值),这应该在 colModel

中设置为 key:true

编辑:如果您对此有困难,请post一些数据以查看发生了什么。

同时指定使用哪个版本的 jqGrid