How to filter bool column in grid?

Hi great Support,
I have simple grid which has bool column. I am displaying it, as Checkbox



How can i filter this column ?


6 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team August 28, 2020 01:00 PM UTC

Hi Customer, 

Greetings from Syncfusion support. 

You can filter a bool column, by typing either true or false values in the FilterBar and click enter button. This will filter the Boolean column based on your entered true/false value. Please refer the screenshot below, 

 

Or you can also use FilterBarTemplate feature of Grid. With this you can render a SfCheckBox in the FilterBar and you can handle the Filtering operation in Grid based on the checked/unchecked state of SfCheckBox by using the FilterByColumn in the ValueChange handler of SfCheckBox.  

We have prepared a sample based on this scenario. Please download the sample from the link below, 
 
Please refer the codes below, 

<GridColumn Field=@nameof(Order.Datum) HeaderText="Datum" DisplayAsCheckBox="true" Width="150">    <FilterTemplate>        <SfCheckBox TChecked="bool" ValueChange="ValueChange"></SfCheckBox>    </FilterTemplate></GridColumn>
 
public void ValueChange(ChangeEventArgs<bool> args) 
{ 
    Grid.FilterByColumn("Datum""equal", args.Checked); 
} 


Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer

BL Blazor September 5, 2020 01:01 PM UTC

Thank you Renjith,
I made "FilterTemplate" it's working.

But i can only choose true or false, i think there must be also "null"(means all records) option but there is not.

Are there any way to achive this?


RS Renjith Singh Rajendran Syncfusion Team September 7, 2020 07:30 AM UTC

Hi Customer, 

Thanks for your update. 

We suggest you to call the ClearFiltering method of Grid to clear the filtering applied in Grid. In the below code, we have rendered a button in FilterTemplate and clicking the button we have called the ClearFiltering method of Grid with the corresponding column name as parameter. Please refer and use as like the codes below, 

 
<GridColumn Field=@nameof(Order.Datum) HeaderText="Datum" TextAlign="TextAlign.Center" DisplayAsCheckBox="true" Width="150"> 
    <FilterTemplate> 
        <SfCheckBox TChecked="bool" ValueChange="ValueChange"></SfCheckBox> 
        <SfButton OnClick="OnClick">Clear</SfButton> 
    </FilterTemplate> 
</GridColumn> 

public void OnClick(){    Grid.ClearFiltering("Datum");   //clear the filering for the particular column.}

 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



SC Sivakrishnan Charaparambil March 27, 2024 10:14 AM UTC

Hello, I tried the above approach to clear the filter and it is working fine. But the template checkbox is not getting cleared. Is there any way to clear that selection?


Image_2691_1711534434543

Image_2593_1711534456223

Image_7341_1711534403720



SC Sivakrishnan Charaparambil replied to Sivakrishnan Charaparambil March 27, 2024 10:55 AM UTC

Well, found a way to handle it!!

Bind value for the check box and set it to false on ClearFiltersAsync method. Please let me know if there is any way to take care of it without this additional piece of code. 


Image_1684_1711536141355

Image_1047_1711535985401




PS Prathap Senthil Syncfusion Team March 28, 2024 03:45 PM UTC

Hi SivaKrishnan,

Based on the problem you've reported, it seems that the issue has been resolved at your end. Using the bind-value to check or uncheck appears to be the proper way to handle it.

Regards,

Prathap S


Loader.
Up arrow icon