This is a migrated thread and some comments may be shown as answers.

Unable to maintain client row selection in grid

2 Answers 14 Views
This is a migrated thread and some comments may be shown as answers.
Jerald
Top achievements
Rank 1
Jerald asked on 10 Nov 2018, 12:00 AM

I'm using the code from the Telerik documentation to maintain the selected row, but it's not working properly.  Instead of keeping the selected row, it's jumping to the top row in the table after each postback.

 

Here's the markup for the grid:

<telerik:RadGrid runat="server" ID="rgAdList" DataSourceID="sdsRgAdList" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" ShowGroupPanel="True" OnSelectedIndexChanged="rgAdList_OnSelectedIndexChanged" OnPreRender="rgAdList_OnPreRender" OnItemCommand="rgAdList_OnItemCommand">
        <ClientSettings AllowDragToGroup="True" AllowColumnsReorder="True" ReorderColumnsOnClient="True">
            <Selecting AllowRowSelect="True"></Selecting>
            <ClientEvents OnRowSelected="RowSelected"></ClientEvents>
            <ClientEvents OnFilterMenuShowing="filterMenuShowing" OnRowSelected="rgAdList_RowSelected" OnRowCreated="rgAdList_RowCreated" OnRowDeselected="rgAdList_RowDeselected" />
        </ClientSettings>
        <FilterMenu OnClientShown="MenuShowing" />
        <GroupingSettings CaseSensitive="False"></GroupingSettings>
        <PagerStyle AlwaysVisible="True"></PagerStyle>
        <MasterTableView DataKeyNames="mail" DataSourceID="sdsRgAdList">
            <PagerStyle PageSizes="5, 10, 25, 50, 100, 200, 300, 400"></PagerStyle>
            <Columns>
                <telerik:GridBoundColumn DataField="givenName" HeaderText="First Name" SortExpression="givenName" UniqueName="givenName" FilterControlAltText="Filter givenName column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="sn" HeaderText="Last Name" SortExpression="sn" UniqueName="sn" FilterControlAltText="Filter sn column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="mail" ReadOnly="True" HeaderText="Email" SortExpression="mail" UniqueName="mail" FilterControlAltText="Filter mail column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="title" HeaderText="Title" SortExpression="title" UniqueName="title" FilterControlAltText="Filter title column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="department" HeaderText="Department" SortExpression="department" UniqueName="department" FilterControlAltText="Filter department column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="manager" HeaderText="Manager" SortExpression="manager" UniqueName="manager" FilterControlAltText="Filter manager column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

 

Here's the script I'm trying to get to work?

<script type="text/javascript">
 
    function rgAdList_RowSelected(sender, args) {
        var id = args.getDataKeyValue("mail");
 
        var selected = (JSON.parse(sessionStorage.getItem("selectedItems")) != null) ? JSON.parse(sessionStorage.getItem("selectedItems")) : {};
 
        if (!selected[id]) {
            selected[id] = true;
 
            sessionStorage.setItem("selectedItems", JSON.stringify(selected));
        }
    }
 
    function rgAdList_RowDeselected(sender, args) {
        var id = args.getDataKeyValue("mail");
        var selected = JSON.parse(sessionStorage.getItem("selectedItems"));
 
        if (selected[id]) {
            selected[id] = null;
 
             sessionStorage.setItem("selectedItems", JSON.stringify(selected));
        }
    }
 
    function rgAdList_RowCreated(sender, args) {
        var id = args.getDataKeyValue("mail");
        var selected = JSON.parse(sessionStorage.getItem("selectedItems"));
 
        if (selected && selected[id]) {
            args.get_gridDataItem().set_selected(true);
        }
    }

 

Thanks, J

2 Answers, 1 is accepted

Sort by
0
Jerald
Top achievements
Rank 1
answered on 12 Nov 2018, 03:12 PM

Well junk.  I forgot to include the "ClientDataKeyNames".  Below is the updated line.

<MasterTableView DataKeyNames="mail" ClientDataKeyNames="mail" DataSourceID="sdsRgAdList">

 

 

0
Eyup
Telerik team
answered on 14 Nov 2018, 08:24 AM
Hello Jerald,

I suggest that you download and examine the RadGridGetAllSelectedItemsImproved.zip provided in the following post:
https://www.telerik.com/support/code-library/get-selected-items-through-all-pages#1eTU8nr-GUG8zfGgOGbIcA

That should help you resolve the issue.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Jerald
Top achievements
Rank 1
Answers by
Jerald
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or