jqGrid gridComplete:- getRowData - 从数组中获取行单元格值 [英] jqGrid gridComplete:- getRowData - get row cell value from array

查看:19
本文介绍了jqGrid gridComplete:- getRowData - 从数组中获取行单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请 - 需要从 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>"; 
      }

这篇关于jqGrid gridComplete:- getRowData - 从数组中获取行单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆