Hi SyncFusion,
I've enabled `EnablePersistence` to allow selection across multiple pages. Though when checking the "select all" checkbox on page 1, the rows on the current page (page 1) will be selected both visually and logically (which is fine) including the "select all" checkbox. When changing to the next page (page 2) none of the rows are logically selected, but the "select all" checkbox is checked and visually all rows are selected. How do I uncheck the "select all" checkbox when changing to page 2, without clearing the selected rows?
Wanted scenarios:
Hi Susanne,
Greetings from Syncfusion support.
Based on your query, it appears that you are using the EnablePersistence property
to persist records. We recommend using the PersistSelection property of
GridSelectionSettings instead of EnablePersistence to persist the selected
records when navigating from one page to another. This property addresses all
the reported issues you are facing. For more details, please refer to the
attached documentation link and sample for your reference.
Sample: https://blazorplayground.syncfusion.com/embed/rNVKsCstfyKnbvci?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5
Reference: https://blazor.syncfusion.com/documentation/datagrid/selection#checkbox-selection
Kindly get back to us if you have any further queries.
Regards,
Sarvesh
Hi Sarvesh,
I would like to use the "select all" checkbox to only select the items on the current page. So when changing to the next page, then the "select all" checkbox should not be checked, and only the items from the previous page is selected.
Kind Regards,
Susanne
Hi Susanne,
From your query, we suspect that you want to select and maintain first page record while navigating pages. Based on your requirement we have achieved in the below way .kindly refer to the below code snippet and sample for your reference.
|
<SfGrid @ref="@Grid" DataSource="@Orders" AllowPaging="true" Height="315"> <GridSelectionSettings CheckboxOnly="true"></GridSelectionSettings>
<GridEvents RowSelected="RowSelectHandler" PageChanging="PageChangingHandler" RowDeselected="RowDeselectHandler" DataBound="Data" TValue="Order"></GridEvents> -------- </SfGrid>
@code {
SfGrid<Order> Grid; public List<Order> Orders { get; set; } List<int> SelectIndex { get; set; }
public bool flag { get; set; } = true;
List<int?> GetSelectedrecordsPrimaryID { get; set; } = new List<int?>();
public async Task Data(object args) { var Source = await Grid.GetCurrentViewRecords(); var IndexNum = 0; SelectIndex = new List<int>();
foreach (var record in Source) { if (GetSelectedrecordsPrimaryID.Contains(record.OrderID)) { SelectIndex.Add(IndexNum); } IndexNum++; }
await Grid.SelectRows(SelectIndex.ToArray());
} public async Task RowSelectHandler(RowSelectEventArgs<Order> args) {
var datas = args.Datas;
if (datas != null) { foreach (var item in datas) { if (!(GetSelectedrecordsPrimaryID.Contains(item.OrderID))) { GetSelectedrecordsPrimaryID.Add(item.OrderID); } } } }
public async Task RowDeselectHandler(RowDeselectEventArgs<Order> args) {
if (flag) { var datas = args.Datas;
if (datas != null) { foreach (var item in datas) { if (GetSelectedrecordsPrimaryID.Contains(item.OrderID)) { GetSelectedrecordsPrimaryID.Remove(item.OrderID); } } } } flag = true;
}
public void PageChangingHandler(GridPageChangingEventArgs args) { flag = false; }
}
|
Reference:
https://blazor.syncfusion.com/documentation/datagrid/selection#multiple-selection-based-on-condition
https://blazor.syncfusion.com/documentation/datagrid/events#databound
https://blazor.syncfusion.com/documentation/datagrid/events#rowselected
https://blazor.syncfusion.com/documentation/datagrid/events#rowdeselected
If you have any further queries, please get back to us.
Regards,
Sarvesh