how to get row id of selected row in jqgrid
Asked Answered
C

1

6

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?

<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();           
    }
Carissacarita answered 11/3, 2013 at 13:53 Comment(0)
A
23

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

and #list is the id of your grid.

ref1 , ref2

Abm answered 11/3, 2013 at 14:1 Comment(2)
i am calling this method but when i debug it selectedRowId is undefined why is that? i copy pasted your code and changed the name of the grid id and the column nameCarissacarita
can you post some code or a jsfiddle in your question? it will be much helpfulAbm

© 2022 - 2024 — McMap. All rights reserved.