jQuery jqGrid gridComplete:- getRowData - 从数组中获取行单元格值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15285282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jqGrid gridComplete:- getRowData - get row cell value from array
提问by Charlez
Please - need syntax for setting variables from jqGrid getRowData property
请 - 需要从 jqGrid getRowData 属性设置变量的语法
Looping thru rows - just need to pull the ID and Phrase column values into variables
循环遍历行 - 只需要将 ID 和 Phrase 列值提取到变量中
gridComplete: function () {
var allRowsInGrid = $('#list').jqGrid('getRowData');
for (i = 0; i < allRowsInGrid.length; i++) {
pid = allRowsInGrid[i].ID;
vPhrase = allRowsInGrid[i].Phrase;
vHref = "<a href='#' onclick='openForm(" + pid + ", " + vPhrase + ")'>View</a>";
}
},
Was able to get ID easy enough with getDataIDs :-)
能够使用 getDataIDs 轻松获取 ID :-)
Need help with getting specific column values for pid and vPhrase for i
需要帮助获取 pid 和 vPhrase for i 的特定列值
Cheers
干杯
回答by Kris
Try this:
尝试这个:
var ids = jQuery("#list").jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++)
{
var rowId = ids[i];
var rowData = jQuery('#list').jqGrid ('getRowData', rowId);
console.log(rowData.Phrase);
console.log(rowId);
}
Please Note: If your goal is to add a link to cell which calls a javascript method you can achieve this by using formatter
like given below, formatter should be added to colModel like you add other column properties like name,index,width,align etc, so you can avoid the iteration over row data
请注意:如果您的目标是添加一个链接到调用 javascript 方法的单元格,您可以使用formatter
下面给出的方法来实现这一点,应该将格式化程序添加到 colModel,就像您添加其他列属性(如名称、索引、宽度、对齐等)一样,这样您就可以避免对行数据进行迭代
formatter: function(cellvalue, options, rowObject) {
return "<a href='#' onclick='openForm("
+ rowObject.ID + ", "
+ rowObject.Phrase
+ ")'>View</a>";
}
回答by Bhushan
This is what I use when I want to get Data by RowID
for specific Cell
.
当我想RowID
为特定的Cell
.
var selRow = jQuery("#list10").jqGrid('getGridParam','selarrrow'); //get selected rows
for(var i=0;i<selRow.length;i++) //iterate through array of selected rows
{
var ret = jQuery("#list10").jqGrid('getRowData',selRow[i]); //get the selected row
name = ret.NAME; //get the data from selected row by column name
add = ret.ADDRESS;
cno = ret.CONTACTNUMBER
alert(selRow[i] +' : ' + name +' : ' + add +' : ' + cno);
}