Unable to maintain client row selection in grid

3 posts, 0 answers
  1. Jerald
    Jerald avatar
    32 posts
    Member since:
    Jan 2016

    Posted 09 Nov 2018 Link to this post

    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. Jerald
    Jerald avatar
    32 posts
    Member since:
    Jan 2016

    Posted 12 Nov 2018 in reply to Jerald Link to this post

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

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

     

     

  3. Eyup
    Admin
    Eyup avatar
    3756 posts

    Posted 14 Nov 2018 Link to this post

    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.
Back to Top