I'm currently working on a project that involves taking the value from a specific column of a jqgrid. I've been told you should use 'getCell' for this, but instead of giving me a value, it always returns false. Can anyone help me solve this? My code to render my JqGrid is below:
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 });
}
}
});
},
};
The getCell return false in two cases: 1. If the column name can't be found in colModel or 2. the row id can not be found
For this purpose it is a good idea to have a column or data from the response, which acts as id.
When using local data as in your case it is a good idea to have set key:true in colModel array in order to work this correct.
Also my recommendation is to have a column which will act as id (be a sure it have unique value) and this should be set as key:true in colModel
EDIT: If you have difficulties with this, please post some data in order to look what is happen.
Also specify which version of jqGrid is used