How to change the data source for checkbox filter popup in Grid?
You can dynamically change the filter data source for the checkbox filter module with the custom data. This can be achieved by assigning a custom dataSource to the filter module in the actionBegin event for the requestType – “filterbeforeopen”.
This is demonstrated explained in the below following sample code for the Discontinued column for which checkbox filter is enabled.. In which, the checkbox filter is enabled for the Discontinued column. Custom data is assigned to the dataSource property of the filter module for this column. which Then, it will be displayed in the checkbox filter popup. After that theThe filtered field will be is removed except the custom data source field since because there will not be any filtered filed while when using the custom data source.
<script> // ActionBegin event function function onActionBegin(args: any) { // Check if the request type and column name areis filtered and Discontinued respectively if (args.requestType === "filterbeforeopen" &&args.columnName === "Discontinued") { // Assign custom data source to the filter module data source args.filterModel.options.dataSource = [{ Discontinued: true }, { Discontinued: false }]; // Remove filtered field except custom data source field args.filterModel.options.filteredColumns = args.filterModel.options.filteredColumns.filter( function(col) { if (col.field == "Discontinued") { return true; } return false; }); } } </script>
Output
You can find the samples here: