Here, I have a datatable with checkbox column. I want to select/unselect checkbox on row selection & vice vera. but when I select row and set checkbox value to ‘on’ It doesnot fire onChange event. Please provide solution for it.
when I select row and set checkbox value to ‘on’ It doesnot fire onChange
I’m not quite sure what you mean by this, since the datatable does not have an onChange event, and the onCheck event does get triggered.
Considering the desired functionality, the best way to approach your case would be the following: Code Snippet.
Here is the overall principle of how this works:
As you check a row trigger the onAfterSelect event, the same goes for unchecking the row → trigger the onAfterUnSelect event
As you select a row trigger the onCheck event and change the value of the actual checkbox, the same logic is applied as you unselect the row.
Ensure that the code does not enter a loop since you are cycling selections and checks.
In the case you want to make use of the master checkbox some additional logic is required: a custom master checkbox needs to be implemented and the appropriate checks need to be done in the onCheck event (check master checkbox as you check every row)