Hi Support,
I am following this example;
https://blazor.syncfusion.com/demos/datagrid/checkbox-selection?theme=bootstrap4&_ga=2.187272872.1267378923.1696157377-261107084.1690022540&_gl=1*1t7k8si*_ga*MjYxMTA3MDg0LjE2OTAwMjI1NDA.*_ga_R3Q3BGFFC9*MTY5NjE2NDc1OC4yOS4xLjE2OTYxNjU4ODIuNjAuMC4w*_ga_41J4HFMX1J*MTY5NjE2NDc1Ny4zNi4xLjE2OTYxNjU4ODIuMC4wLjA.
Here is problem step by step;
First i selected "Select All" checkbox
Now first page records are selected. Not other page rows.
But when i move to second page.
Second page records are automaticaly selecting which is not convinient for me. Becasue user may think that 3th, 4th ... pages are also selected, but they are not.
How can i prevent automatic selection on next page when changing pages.
Hi,
Based on your concern, we would like to clarify that in your shared demo link,
you used the PersistSelection setting as 'true' in the GridSelectSettings
component. If PersistSelection is enabled, the first-page records are selected
using the SelectAll checkbox, and when moving to the next page, records are
also automatically selected. This is the default behavior of the grid. If you
want to select only the records on the current page, we suggest setting PersistSelection
to 'false.' Please refer to the code snippet below.
|
<SfGrid DataSource="@GridData" AllowSelection="true" AllowPaging="true"> <GridSelectionSettings CheckboxOnly="true" PersistSelection="true"></GridSelectionSettings> </SfGrid> <SfGrid DataSource="@GridData" AllowSelection="true" AllowPaging="true"> <GridSelectionSettings CheckboxOnly="true" PersistSelection="false"></GridSelectionSettings> </SfGrid>
|
Regards,
Prathap S
But if i set
PersistSelection to 'false'
then here is the behaviour;
User select first page fully;
Then user select second page;
User decide "ok i have to add these records too".
But first page records are already unselected.
What i want is to persist first page selction, but not automaticaly select new pages records when i switch to other pages. Are there any way to prevent automatic selection?
Based on your requirement we have achieved 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
Nice workaroud. But i belive this requiremet is very natural one. I belive it has to be build in feature.
But thanks for solution.
Based on your request, we would like to clarify that when 'persistselection' is set to false and you move to the next page, the current page selections will be unselected. This is the default behavior. For your specific requirement, we have modified the custom solution.