我想通过jqGrid中的单元格内容(不是通过选定的行)获取行ID。如何获得按行的行ID在jqGrid中的数据(不是通过所选的行)
通过PRODUCTID
,我可以得到该行的ID。
例如对于PRODUCTID
是ABCD
,我可以得到2.
列PRODUCTID
是唯一的。
请给我一些建议。
非常感谢。
我的代码示例:
$("#project_jqGrid").jqGrid({
url: 'project/projectQuery.php',
mtype: "POST",
datatype: "json",
page: 1,
colModel: [
{ label : "PRODUCTLINE",
//sorttype: 'integer',
name: 'PRODUCTLINE',
//key: true,
width: 100,
editable:true,
editoptions:{readonly:'readonly'}
},
{ label : "GPOWNER",
//sorttype: 'integer',
name: 'GPOWNER',
//key: true,
width: 150,
editable:true,
editoptions:{readonly:'readonly'}
},
{ label : "PRODUCTID",
//sorttype: 'integer',
name: 'PRODUCTID',
key: true,
width: 100,
editable:true,
editoptions:{readonly:'readonly'}
},
],
loadComplete: function() {
$.ajax({
dataType: 'json',
url : "project/projectDifferQuery.php", // your php file
type : "GET", // type of the HTTP request
success : function(data){
// I can get PRODUCTID from mysql database
// I want to get rowid to change cells color by PRODUCTID
// ........
// Change Cells Color(I need to get '5' by position of PRODUCTID)
//$('#project_jqGrid').jqGrid('setCell',5,"GPOWNER","",{'background-color':'#FF4545'});
}
});
},
loadonce: true,
viewrecords: true,
width: 'auto',
height: 'auto',
rowNum: 20,
pager: "#project_jqGridPager"//,
});
>版本: - 5.1.1的jqGrid
谢谢奥列格。但我不知道你的意思。你能给我一些建议吗?谢谢。 – Leo
@Leo:不客气!您应该将问题的文本附加到用于创建jqGrid的** JavaScript代码**和JSON数据的示例中。 JavaScript代码应该包含'colModel'参数。来自'colModel'元素的一个对应于'ProductID'列。你应该在列中加上'key:true'。 – Oleg
感谢您的回复。我添加代码示例并修改一些说明。我主要需要通过单元格的内容获取rowid(colName是PRODUCTID)。 – Leo