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
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.
The provided information will help us analyze the problem, and provide you a solution as early as possible.
Regards,
Renjith R
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
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;
}
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.
Please check the above suggestion from your side and get back to us if you need further assistance.
Regards,
Renjith R