如何获取jqgrid中所选行的行ID

时间:2013-03-11 13:53:57

标签: jquery jqgrid

我正在编写此代码并在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();           
    }

1 个答案:

答案 0 :(得分:22)

试试这个:

var myGrid = $('#list'),
selectedRowId = myGrid.jqGrid ('getGridParam', 'selrow'),
cellValue = myGrid.jqGrid ('getCell', selectedRowId, 'columnName');

其中columnName是您在name

colModel属性中提供的列

#list是您网格的ID。

ref1ref2