DataGrid header selection checkbox doesn't work with paging

1 Answer 127 Views
Grid
Yiheng
Top achievements
Rank 2
Iron
Iron
Iron
Yiheng asked on 17 Nov 2022, 01:53 PM

When clicking the header selection checkbox, items of the current page are checked, but the header checkbox itself is not checked.

1 Answer, 1 is accepted

Sort by
0
Accepted
Vessy
Telerik team
answered on 21 Nov 2022, 07:03 AM

Hi, Yiheng,

You can see how to implement a `selectAll` button which selection state is updated properly when all items are selected in the following demo. Can you compare it with your actual setup and see how they differ?

https://www.telerik.com/kendo-react-ui/components/grid/selection/#toc-customizing-the-selection

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Yiheng
Top achievements
Rank 2
Iron
Iron
Iron
commented on 21 Nov 2022, 09:13 AM

Hi Vessy, I've made that demo paginated, check the header selection button here https://stackblitz.com/edit/react-v7yj55?file=app%2Fmain.jsx
Vessy
Telerik team
commented on 23 Nov 2022, 08:53 AM

Thank you for the update, Yiheng. In the provided demo the header checkbox value is updated only if all items are selected, while in the paging scenario you are changing the selection only of the items on the first page. You can change the logic applied to the `headerSelectionValue` prop to update the header checkbox if any of the data items are checked (instead of if all items are checked) like follows:

         headerSelectionValue={
            dataState.findIndex((item) => selectedState[idGetter(item)]) != -1
          }

You can test it here:

https://stackblitz.com/edit/react-v7yj55-jepzky?file=app%2Fmain.jsx

Please note that with the sample above the header checkbox will remain checked event if you do not have selected items on the current page, but you have active checkboxes in some other pages. For example, in order to avoid this you can keep the headerChecked value in the state and update based on the items on the current page.

I hope this helps.

 

 

Tags
Grid
Asked by
Yiheng
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Vessy
Telerik team
Share this question
or