Checkbox Loses selection after datagrid sort

Hello
Apologies for repeating a Previous Post but I thought I would give examples as well as screenshots as it may help others understand and give input. My issue is that I have added a checkbox to a datagrid that allows you to select one or more records within a grid and stores the Id in a page property. If the grid is sorted after a checkbox is ticked the checkboxes are cleared even though the page property still knows which are ticked. I would like to be able to retick the boxes using the page property.
By way of an example i have taken the sample CRUD app and added the column on the order details page. When you click on a checkbox you will see that it displays the id in a label (screenshot below)


However, if you then click on the heading of the Id field to sort it, you will see that the page property keeps the data but the checkboxes are now cleared.

If it helps I can share the sample app for people to try but your help is appreciated.

You need to set the Value property of the Checkbox if you want it to keep its checked state.

Please correct me if i missing something but i have tried that and it doesnt work. By way of example i have done as you have stated on the sample app where i have set the value for the checkbox to be the id field within the datagrid. please bear in mind that the id field is an integer


And then I have run the app

and as you can see all the boxes are now checked (not the behaviour i am looking for). I then start to untick some of the boxes

and here you can see that the id column now says false instead of the original id. I then click the id heading to resort the columns

and as you can see the boxes are now all ticked again, the id field no longer says false where they were unticked.

I have also tried setting the property for the column outside of the template page and it still acts the same.

Are you inferring that I need to have a boolean field within the dataset in order for this to work?

You shouldn't set the Value of the checkbox to the ID of your data item. The Value will update the ID when the user checks the checkbox.

You should create a separate property which stores the checked checkboxes:

Then set the Value of the checkbox to checkedValues[data.Id]

Then checkedValues will contain the ID of the checked items e.g.:

{
   "1": true,
   "2": true,
   "3": false
}
``
1 Like