Select all checkbox is checked after page change, but rows are not logically selected

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:

  • Allow user to select rows across multiple pages.
  • Allow user to select all rows on current page.
  • When changing page, the "select all" checkbox should re-evaluate whether it is checked or not, based on the rows on the current page.'

Kind Regards, Susanne.

3 Replies

SP Sarveswaran Palani Syncfusion Team November 10, 2023 12:58 PM UTC

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




SO Susanne Olsen November 20, 2023 07:55 AM UTC

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



SP Sarveswaran Palani Syncfusion Team November 22, 2023 03:38 AM UTC

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


Attachment: GridSelection_2efc931e_7708d14e.zip

Loader.
Up arrow icon