Javascript JQuery 和 JqGrid 从行中检索数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3758915/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:02:01  来源:igfitidea点击:

JQuery and JqGrid retrieve data from row

javascriptjqueryjqgrid

提问by michele

How I can retrieve data from jqgrid row, if I have only the number of the row?

如果我只有行号,如何从 jqgrid 行中检索数据?

For example, what do I have to do if I want the id column of the 3rd row?

比如我想要第3行的id列怎么办?

回答by Oleg

You can get the data by row id. So you can do following:

您可以通过行 id 获取数据。因此,您可以执行以下操作:

var index = 2; // zero-based index of row so it means the 3rd row
var rowId = jQuery('#list tr:eq('+index+')').attr('id');

(here I suppose that the <table>element of your jqGrid has id="list"). After you know the id of the row you can get the row data with respect of getRowDatamethod or the data from one cell only with respect of getCellmethod:

(在这里我假设<table>您的 jqGrid 元素具有 id="list")。知道行的 id 后,您可以通过getRowData方法获取行数据,或者仅通过getCell方法获取来自一个单元格的数据:

var dataFromTheRow = jQuery('#list').jqGrid ('getRowData', rowId);
var dataFromCellByColumnIndex = jQuery('#list').jqGrid ('getCell', rowId, 7);
var dataFromCellByColumnName = jQuery('#list').jqGrid ('getCell', rowId, 'Tax');

回答by Luis Eduardo

Please, be carefull with methods getCelland getRowDataif case you are editing the row or cell. "This will return the cell content and not the actuall value of the input element."

如果您正在编辑行或单元格,请小心使用getCellgetRowData方法。“这将返回单元格内容而不是输入元素的实际值。”