Select all rows with button

Hello,

I would like add a context menu to my grid with "Select all rows" option.

I use this code to select the rows:

    public async Task OnContextMenuClick(ContextMenuClickEventArgs<AnyagRendelesListItemDto> args)

    {

        if (args.Item.Id == "ctxSelectAll")

        {

            await this.PrimaryGrid.SelectRowsByRangeAsync(0);

        }

    }

My problem is that the select duration is ~9 seconds for only 22 rows.

Can I speedup the select method?

Thank you very much for help!

BR, SZL


4 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team May 24, 2022 07:12 AM UTC

Hi SZL,


Greetings from Syncfusion support.


We checked this scenario by creating a sample using your shared codes. We could not reproduce the reported 9s delay when selecting 22 rows in grid. We are attaching the sample which we have tried in this ticket.


Kindly download and refer the attached sample and if you are still facing difficulties then the following details would be helpful for us to proceed further.


  1. Share a simple issue reproducing sample for us to validate.
  2. Share the exact scenario you are reproducing this reported problem.
  3. Share the complete grid rendering codes and model class codes.


The provided information will help us analyze the problem, and provide you a solution as early as possible.


Regards,

Renjith R


Attachment: ServerApp_39e6b69c.zip


SZ SZL replied to Renjith Singh Rajendran May 26, 2022 02:02 PM UTC

Hello,

I succeed to locate the problem. This is my grid code:


    <SfGrid ID="Grid"

            @ref="PrimaryGrid"

            TValue="AnyagRendelesListItemDto"

            Query="GridQuery"

            AllowPaging="true"

            AllowSorting="true"

            AllowFiltering="true"

            AllowReordering="true"

            AllowResizing="true"

            AllowExcelExport="true"

            AllowPdfExport="true"

            ShowColumnChooser="true"

            ContextMenuItems="@GetGridContextMenuItems()"

            Toolbar="@GetPrimaryGridToolbarItems(false,false,false)"

            Height="100%"

            Width="100%">

        <SfDataManager @ref="PrimaryDataManager"

                       Url="api/anyagrendeles/list"

                       Adaptor="Adaptors.UrlAdaptor"

                       Offline=false />

        <GridEditSettings AllowAdding="false" AllowDeleting="false" AllowEditing="false"></GridEditSettings>

        <GridPageSettings PageSize="50"></GridPageSettings>

        <GridSelectionSettings PersistSelection="true" Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings>

        <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.FilterBar"></GridFilterSettings>

        <GridEvents OnToolbarClick="PrimaryToolbarClick"

                    OnActionBegin="PrimaryGridActionBeginHandlerAsync"

                    OnActionComplete="PrimaryGridActionCompletedHandlerAsync"

                    ContextMenuItemClicked="OnContextMenuClick"

                    ContextMenuOpen="OnContextMenuOpen"

                    RowSelected="PrimaryGridRowSelectHandler1"

                    RowDeselected="PrimaryGridRowDeSelectHandler1"

                    OnLoad="PrimaryGridLoadHandler"

                    TValue="AnyagRendelesListItemDto" />

        <GridColumns>

            <GridColumn Field=@nameof(AnyagRendelesListItemDto.Id) IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="140" Visible="false"></GridColumn>

            <GridColumn Field=@nameof(AnyagRendelesListItemDto.Sorszam) AllowEditing=false Width="90px" HideAtMedia="(min-width: 700px)" AutoFit="true" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>

        </GridColumns>

    </SfGrid>


@code {

    public virtual async Task PrimaryGridRowSelectHandler1(RowSelectEventArgs<AnyagRendelesListItemDto> args)

    {

        // yes, it is empty

    }


    public virtual async Task PrimaryGridRowDeSelectHandler1(RowDeselectEventArgs<AnyagRendelesListItemDto> args)

    {

        // yes, it is empty

    }

}

With the above code the select all function is slow.

When I remove the  RowSelected ​event handler, the select all function will be fast.

(The content of the PrimaryGridRowSelectHandler1 does not matter, an empty block can cause the problem).


Unfortunatelly I cannot reproduce this in your example, maybe some another settings and this row select handler  can cause this slow select together.

Thank you!


BR, SZL



SZ SZL May 27, 2022 10:48 AM UTC

Hello,

It seems, I find the solution. By default the grid renders in every row selected event call. PreventRender = true solves the problem.

There are any disadvantage using PreventRender = true?

Thank you for help! 


    private void OnRowSelected(RowSelectEventArgs<Order> args)
    {
        args.PreventRender = true; //without this, you may see noticeable delay in selection with 75 rows in grid.
        SelectedOrder = args.Data;
    }


RS Renjith Singh Rajendran Syncfusion Team May 27, 2022 11:56 AM UTC

Hi SZL,


We suspect that you are using wasm blazor application. If so, then we suggest you to handle as like suggested in the below documentation when bind Grid with RowSelected event to improve performance.

https://blazor.syncfusion.com/documentation/datagrid/webassembly-performance#avoid-unnecessary-component-renders-after-grid-events


Please check the above suggestion from your side and get back to us if you need further assistance.


Regards,

Renjith R


Marked as answer
Loader.
Up arrow icon