jqGrid gridComplete:- getRowData - 从数组中获取行单元格值

2022-01-19 00:00:00 jquery javascript jqgrid

请 - 需要从 jqGrid getRowData 设置变量的语法属性

Please - need syntax for setting variables from jqGrid getRowData property

循环遍历行 - 只需将 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 :-)

在获取 i 的 pid 和 vPhrase 的特定列值方面需要帮助

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>"; 
      }

相关文章