jqGrid gridComplete: - getRowData - 从数组中获取行单元格值 [英] jqGrid gridComplete:- getRowData - get row cell value from array
问题描述
请 - 需要从jqGrid设置变量的语法getRowData
property
Please - need syntax for setting variables from jqGrid getRowData property
Looping thru行 - 只需要将ID和Phrase列值拉入变量
Looping thru rows - just need to pull the ID and Phrase column values into variables
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>";
}
},
使用getDataIDs能够轻松获取ID: - )
Was able to get ID easy enough with getDataIDs :-)
需要帮助获取pid和vPhrase的特定列值i
Need help with getting specific column values for pid and vPhrase for i
干杯
推荐答案
试试这个:
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);
}
请注意:如果您的目标是添加一个指向调用的单元格的链接javascript方法你可以通过使用 formatter
实现这一点,如下所示,格式化程序应该添加到colModel,就像你添加其他列属性,如名称,索引,宽度,对齐等,所以你可以避免迭代行数据
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
formatter: function(cellvalue, options, rowObject) {
return "<a href='#' onclick='openForm("
+ rowObject.ID + ", "
+ rowObject.Phrase
+ ")'>View</a>";
}
这篇关于jqGrid gridComplete: - getRowData - 从数组中获取行单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!