Wijmo's FlexGrid converts columns of the boolean data type to checkboxes inside of each cell. You can create a 'master' checkbox, which resides inside the header cell of that column, that can be used to select or deselect all of the cells in that column.
1. Create a column in FlexGrid that is a boolean data type
2. Prevent sorting of the column on click of the header
3. Add the checkbox to the column header
4. Apply the checkbox value of the master checkbox to all other checkboxes on click and vice versa
In order for a master checkbox to work, the column that the master checkbox will be placed in must have checkboxes in its cells. This is done by making sure the column is a boolean data type. In this article, we'll make the Active column a boolean data type.
This method will return us a Wijmo ObservableArray, where the 'active' property of each object is set to a boolean value, replacing all of the values in the Active column with checkboxes.
Next, we'll use the itemFormatter event to cancel the click event of the boolean column header. ItemFormatter gets run when FlexGrid initializes, meaning that it will perform these actions before the customer gets a chance to view or interact with the grid.
This portion of code will check to see, as it iterates through creating each column, if the current column is a boolean column. If it is boolean, then it will turn off the ability to sort the column by clicking on the header. This needs to be done to allow for the user to interact with the master checkbox without altering the layout of the column.
Now that sorting has been prevented, and we're sure that we're in the right column, we can insert the master checkbox. The master checkbox will have 3 states; checked (all checkboxes are checked), unchecked (all checkboxes are unchecked) and partially checked (some checkboxes are checked).
This will add the master checkbox to the header of the boolean column, as well as set the value of the master checkbox based on the values of the checkboxes in that column.
Now that the master checkbox is in place, all that is left is to add an EventListener to it. When it gets clicked, it will iterate through and set all the chekboxes to the status of the master checkbox (either checked or unchecked).
The flex.beginUpdate() method lets FlexGrid know that the data is going to be changed, so don't update the FlexGrid until endUpdate() method gets called. This means that the grid won't refresh every single time the checkbox gets updated, but that the grid will wait until all of the changes are done, and do one single update. This helps performance for FlexGrid.
You can find a live sample of this project at this location: https://stackblitz.com/edit/wijmo-knowledgebase-angular-flexgrid-checkbox-header