We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: JavaScript - EJ 2 |
Control: 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

Custom checkbox filter data

You can find the samples here:

JavaScript (ES5) sample

Angular sample

ASP.NET Core sample

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile