如何通过 jqgrid 中的行数据获取行 ID(不是通过选定的行)
How to get row ID by row Data in jqgrid (Not by selected row)
我想通过 jqGrid 中单元格的内容获取行 ID(而不是通过选定的行)。
通过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"//,
});
> 版本:- jqGrid 5.1.1
理解你想要得到的东西有点困难 - 我想你的意思是 rowIndex,所以这里有一些方法可以提供帮助。
方法
getGridRowById(字符串rowid)
Return id = rowid 的行作为文档对象
getInd(string rowid, [boolean rowcontent])
Returns 由网格 id row - rowid 指定的网格 table 中行的索引。如果 rowcontent 设置为 true 它 returns 行文档对象
如果您将行作为文档对象,您可以获得索引和 ID。假设rowdata为文档行,则
rowdata.rowIndex是指数
rowdata.id是id
如果 ProductID
是唯一的并且网格包含 ProductID
作为 colModel
中的列名称,那么建议将 key: true
添加到列定义中。它强制 jqGrid 使用 ProductID
中的值作为 rowid。
了解 jqGrid 的代码 需要 为 jqGrid 的每一行(<tr>
元素)设置唯一的 id
属性很重要。参见 here。因此jqGrid的输入数据必须包含rowid信息。 jqGrid 的输入数据有很多可供选择的格式。以最常见的方式,输入数据应包含 id
属性。如果您的输入数据使用 ProductID
作为行的唯一 id,那么您可以添加选项 jsonReader: { id: "ProductID" }
来通知 jqGrid。在这种情况下,您不需要将 ProductID
作为列包含在 colModel
.
中
我想通过 jqGrid 中单元格的内容获取行 ID(而不是通过选定的行)。
通过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"//,
});
> 版本:- jqGrid 5.1.1
理解你想要得到的东西有点困难 - 我想你的意思是 rowIndex,所以这里有一些方法可以提供帮助。
方法
getGridRowById(字符串rowid)
Return id = rowid 的行作为文档对象
getInd(string rowid, [boolean rowcontent])
Returns 由网格 id row - rowid 指定的网格 table 中行的索引。如果 rowcontent 设置为 true 它 returns 行文档对象
如果您将行作为文档对象,您可以获得索引和 ID。假设rowdata为文档行,则
rowdata.rowIndex是指数
rowdata.id是id
如果 ProductID
是唯一的并且网格包含 ProductID
作为 colModel
中的列名称,那么建议将 key: true
添加到列定义中。它强制 jqGrid 使用 ProductID
中的值作为 rowid。
了解 jqGrid 的代码 需要 为 jqGrid 的每一行(<tr>
元素)设置唯一的 id
属性很重要。参见 here。因此jqGrid的输入数据必须包含rowid信息。 jqGrid 的输入数据有很多可供选择的格式。以最常见的方式,输入数据应包含 id
属性。如果您的输入数据使用 ProductID
作为行的唯一 id,那么您可以添加选项 jsonReader: { id: "ProductID" }
来通知 jqGrid。在这种情况下,您不需要将 ProductID
作为列包含在 colModel
.