如何在javascript中获取选定的行ID? [英] How to get the selected row id in javascript?
问题描述
我正尝试使用以下JavaScript函数在单击时从jqgrid获取特定的单元格值.
I'm trying to use the following JavaScript function to get a particular cell value from a jqgrid upon click.
在下面的函数#datagrid
中是存储jqgrid的表.
In the below function #datagrid
is the table where the jqgrid is stored in.
$("#datagrid").click(function(){
var selr = $("#datagrid").getCol('companyid');
alert(selr);
});
我的问题是,当我单击jqgrid时,它将在警报消息中显示jqgrid的所有行ID,但是我只需要从jqgrid中选择的特定公司ID.我该如何进行这项工作?
My problem is when I click the jqgrid it will show ALL row id's from the jqgrid in the alert message, but I only need a particular companyid which was selected from the jqgrid. How do I make this work?
推荐答案
您应该使用getCell
函数从行ID标识的单元格中读取值.
You should use getCell
function to read the value from the cell identified by row id.
因此,您应该尝试执行以下操作:
So, You should try something like this:
$("#datagrid").click(function(){
var grid = jQuery('#datagrid');
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var myCellData = grid.jqGrid('getCell', sel_id, 'MyColName');
});
这篇关于如何在javascript中获取选定的行ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!