Hi, Im trying to select all rows within my datagrid once the select all button has been pressed on the toolbar. I can only seem to get all rows on the first page and that's it.
Heres my code.
<SfGrid @ref="OCHAPPDefaultGrid" DataSource="@OCHAPPUDFs" AllowSelection="true" AllowPaging="true" AllowSorting="true" AllowFiltering="true" AllowMultiSorting="true" Toolbar="@Toolbaritems">
<GridEvents QueryCellInfo="OCHAPPCustomCells" TValue="OCHAPPCFGSummary" OnToolbarClick="@ToolbarClickHandler"></GridEvents>
<GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple" PersistSelection="true" AllowDragSelection="true"></GridSelectionSettings>
<GridPageSettings PageSize="20"></GridPageSettings>
<GridColumns>
<GridColumn Type="ColumnType.CheckBox" Width="30"></GridColumn>
<GridColumn Field=@nameof(OCHAPPCFGSummary.SettingID) HeaderText="ID" TextAlign="TextAlign.Left" Width="120"></GridColumn>
<GridColumn Field=@nameof(OCHAPPCFGSummary.ExistInDB1) HeaderText="@PageData.Db1ConnnectionProfile.DatabaseName" Width="120"></GridColumn>
<GridColumn Field=@nameof(OCHAPPCFGSummary.DB1Value) HeaderText="DB1 Value" Width="120"></GridColumn>
<GridColumn Field=@nameof(OCHAPPCFGSummary.ExistInDB2) HeaderText="@PageData.Db2ConnnectionProfile.DatabaseName" TextAlign="TextAlign.Left" Width="130"></GridColumn>
<GridColumn Field=@nameof(OCHAPPCFGSummary.DB2Value) HeaderText="DB2 Value" TextAlign="TextAlign.Left" Width="120"></GridColumn>
<GridColumn Field=@nameof(OCHAPPCFGSummary.Databasedropdown) HeaderText="Update DB1/2" EditType="EditType.DropDownEdit" Width="150">
<Template>
<SfDropDownList Placeholder="Select DB" TItem="string" TValue="string" DataSource="@Countries">
@*<DropDownListEvents TValue="string" TItem="string" ValueChange="ValueChange"></DropDownListEvents>*@
<DropDownListFieldSettings Text="Update Datebase" Value="Databasedropdown"></DropDownListFieldSettings>
</SfDropDownList>
</Template>
</GridColumn>
</GridColumns>
</SfGrid>
This is the event i am using...
public async Task ToolbarClickHandler(ClickEventArgs args)
{
if (args.Item.Text == "Select All")
{
var recordNumber = OCHAPPUDFs.Count;
await this.OCHAPPDefaultGrid.SelectRowsByRangeAsync(0, recordNumber );
}
}
Hi Max,
Greetings from Syncfusion
Query: “Im trying to select all rows in my datagrid when select all button in the toolbar has been clicked”
We would like to inform that currently we don’t have direct support to perform selection programmatically using SelectRowAsync method. However we have provided an sample level solution to achieve your requirement. Kindly check the below attached sample and code snippet for your reference.
|
<SfButton @onclick="click">Select All Record</SfButton>
<SfGrid DataSource="@Orders" @ref="Grid" AllowPaging="true" AllowSorting="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315"> </SfGrid>
@code { public List<Order> Orders { get; set; } public SfGrid<Order> Grid { get; set; }
public bool ContinuePaging = true; public async Task click() {
ContinuePaging = true; var CurrentPage = Grid.PageSettings.CurrentPage; decimal pagesize = Grid.PageSettings.PageSize; await Grid.GoToPageAsync(CurrentPage); var TotalRec = Grid.DataSource.Count(); double PageCount = (double)Math.Ceiling(TotalRec / pagesize);
for (int i = 1; i <= PageCount; i++)
{
List<Order> Rows = await Grid.GetCurrentViewRecordsAsync(); // returns the current view data
for (int j = 0; j < Grid.PageSettings.PageSize; j++)
{
foreach (var a in Rows)
{ var value = a.OrderID; var rowIndex = Grid.GetRowIndexByPrimaryKeyAsync(value); int rvalue = Convert.ToInt32(rowIndex.Result); await Grid.SelectRowAsync(rvalue); } } await Grid.GoToPageAsync(i + 1);
await Task.Delay(200);
}
}
} |
Also we
have considered your requirement “Need to provide support for select records
in another pages using SelectRows method” as an usability improvement feature and logged the
improvement report for the same. This feature will included in any of our upcoming release. Until then we appreciate your patience.
You can now track the current status of your request, review the
proposed resolution timeline, and contact us for any further inquiries through
this link.
You can also communicate with us regarding the open feature at any time using our above feedback report page. We do not have an immediate plan to implement this feature and it will be included in any of our upcoming releases. Please cast your vote to make it count so that we will prioritize the improvement for every release based on demands.
We are closing this forum for now. You can communicate with us regarding the open features at any time using the above Feature Report page.
Please reopen this forum if you face any difficulties while implementing the above suggested solution.
Regards,
Monisha