jQuery 如何在jqgrid中获取所选行的行ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15340378/
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
how to get row id of selected row in jqgrid
提问by Vishweshwar Kapse
I am writing this code and calling the method on rowdoubleclick of the jqgrid. I have also given all the tags and the column names of my jqgrid. Can you help me figure out why I am getting "undefined" when I alert the values?
我正在编写此代码并在 jqgrid 的 rowdoubleclick 上调用该方法。我还给出了我的 jqgrid 的所有标签和列名。你能帮我弄清楚为什么当我提醒值时我得到“未定义”吗?
<cc1:JQGrid ID="grdUserDetails" runat="server" Width="770px" Height="350px" ClientSideEvents-RowDoubleClick="ForwardDetails">
<Columns>
<cc1:JQGridColumn DataField="VisitorID" HeaderText="ID" TextAlign="Left" PrimaryKey="true"
Visible="false" Searchable="false">
</cc1:JQGridColumn>
<cc1:JQGridColumn DataField="PersonName" HeaderText="Visitor" TextAlign="Left">
</cc1:JQGridColumn>
<cc1:JQGridColumn DataField="CompanyName" HeaderText="Company Name" TextAlign="Left">
</cc1:JQGridColumn>
<cc1:JQGridColumn DataField="ContactNumber" HeaderText="Contact Number" TextAlign="Left">
</cc1:JQGridColumn>
<cc1:JQGridColumn DataField="Address" HeaderText="Address" TextAlign="Left">
</cc1:JQGridColumn>
<cc1:JQGridColumn DataField="Email" HeaderText="Email" TextAlign="Left">
</cc1:JQGridColumn>
<cc1:JQGridColumn DataField="DisplayDate" HeaderText="Last Visited on" TextAlign="Left">
</cc1:JQGridColumn>
</Columns>
<PagerSettings PageSize="15" PageSizeOptions="[15,25,50]" />
<ToolBarSettings ShowSearchButton="false" ShowRefreshButton="true" ShowSearchToolBar="true">
</ToolBarSettings>
<AppearanceSettings ShowRowNumbers="true" ></AppearanceSettings>
<SearchToolBarSettings SearchToolBarAction="SearchOnKeyPress" />
</cc1:JQGrid>
function ForwardDetails() {
var PersonName, Address, CompanyName, ContactNumber, Email;
var selectedRowId, cellValue;
var myGrid = $('#grdUserDetails');
selectedRowId = myGrid.jqGrid('getGridParam', 'selrow');
cellValue = myGrid.jqGrid('getCell', selectedRowId, 'Visitor Name');
window.opener.setValues(PersonName, Address, CompanyName, ContactNumber, Email);
window.close();
}
回答by Manish Mishra
try this:
尝试这个:
var myGrid = $('#list'),
selectedRowId = myGrid.jqGrid ('getGridParam', 'selrow'),
cellValue = myGrid.jqGrid ('getCell', selectedRowId, 'columnName');
where columnName
is the column you provided in the name
property of colModel
columnName
您在name
属性中提供的列在哪里colModel
and #list
is the id of your grid.
并#list
为您的网格的ID。