RadGrid AllowMultiRowSelection = "true" not firing ItemCommand for every row

1 Answer 27 Views
Grid
John
Top achievements
Rank 1
John asked on 14 Apr 2024, 10:59 PM

Hello,

I'm working with a RadGrid that has AllowMultiRowSelection set to "true":

<telerik:RadGrid ID="sampleRgId" runat="server" AllowPaging="True" AllowCustomPaging="True" SkinID="Default" 
PageSize="20" AllowAutomaticDeletes="false" AllowAutomaticUpdates="false" AllowMultiRowSelection="true" OnDetailTableDataBind="sampleRgDetailTableDataBind"  RetainExpandStateOnRebind="True" HierarchyLoadMode="ServerOnDemand" EnableViewState="true">
    <ClientSettings>
        <Selecting AllowRowSelect="true" />
        <ClientEvents OnRowSelected="sampleRgRowSelected"
        OnRowDeselected="sampleRgRowDeselected"/>
    </ClientSettings>
    <MasterTableView Name="sample" 
    runat="server" Width="100%" 
    HierarchyLoadMode="ServerOnDemand" ShowHeader="True" 
    ShowFooter="True" AllowPaging="True" 
    AllowCustomPaging="True" PageSize="20" 
    AllowFilteringByColumn="True" DataMember="sampleRgTable"
    EnableHierarchyExpandAll="True" EnableGroupsExpandAll="True" 
    RetainExpandStateOnRebind="True" DataKeyNames="dataKeyOne, dataKeyTwo">
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="uniqueNameOne" Display="True" HeaderStyle-Width="35px" 
            HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
            <telerik:GridBoundColumn HeaderText="Header Text" DataField="dataFieldOne" UniqueName="UniqueNameTwo" 
            SortExpression="UniqueNameTwo" HeaderStyle-Width="50%" FilterControlWidth="70%" />
...


The "sampleRgRowSelected" function looks like this:

asyncfunctionsampleRgRowSelected(sender, args){ let masterTable = $find("<%= sampleRgId.ClientID %>").get_masterTableView();
let itemIndex = args.get_itemIndexHierarchical(); masterTable.fireCommand("SelectRow", itemIndex); }


The "SelectRow" function in the code-behind looks like this:

PrivateSub SelectParentGroup(e As GridCommandEventArgs)
Dim itemIndex as Integer = e.CommandArgument Dim item As GridDataItem = e.Item.OwnerTableView.Items(itemIndex) processData(item) item.Selected = trueEndSub

I'm having two problems with the above when I click the "multi row selection" / "select all" checkbox in the RadGrid:

1- Selected rows aren't staying selected. When I click "Select All," every row is selected at first. After a minute, though, only the last row shows as selected. I'm guessing that is because of the ItemCommand taking some time to fire for each row. Then the final state is only having the last row selected.

2- When I have > 6 rows, not every row is selected. When I click "Select All," the sampleRgRowSelected() JavaScript function runs for every row in the RadGrid, starting with the last row. However, the ItemCommand is not fired for every row in the RadGrid. Only the first 6 rows as well as the last one have had "SelectRow" called on them.

Is there a way to know when "select all" has been selected in a RadGrid? If I knew that, I could just manually call processData and select each item. That would work better because I could also select paginated items when "select all" has been clicked.

Thanks for your time.

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 15 Apr 2024, 12:39 PM

Hello John,

Based on the description, it seems there is a custom implementation for selecting rows on the server which conflicts with the built-in selection functionality. Decide whether you would like to select the rows on the client or the server and stick to that strategy only. This way you will avoid the conflict.

Selection is a client-side functionality of the Grid. That means that selection happens by JavaScript code and the Column used to select rows (GridClientSelectColumn) does not make postbacks.

If you want to select the rows on the Server side using a "Check All" checkbox, you will need to create a Template Column with checkboxes, see https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/selecting/selecting-rows/server-side-selecting-with-a-checkbox

I would also recommend checking out the Selecting Functionality documentation to learn more about the different options the Grid provides out of the box. We have recently updated this section with better examples and explanations.

If you can't find the example you are looking for, please post the complete implementation of the Grid (ItemCommand event, NeedDataSource, page Load, etc.) as well as describe in steps how you'd expect this selection to work and we will advise you accordingly.

Regards,
Attila Antal
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or