Articles in this section
Category / Section

How to change the data source for checkbox filter popup in Grid?

1 min read

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

Custom checkbox filter data

You can find the samples here:

JavaScript (ES5) sample

Angular sample

ASP.NET Core sample

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied