This is a migrated thread and some comments may be shown as answers.

Filter Checkbox Column Type Not Displaying Filter

3 Answers 505 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deon
Top achievements
Rank 1
Deon asked on 09 Oct 2012, 01:27 AM
I have been reading through the changes made to the programmatic filtering and have encountered an issue with regards to a checkbox column type within a RadGridView.

I would like to be able to filter the records that are checked but also have that show up in the filter UI.  At this time, I have followed the instructions on how to set the filter, the filter icon highlights and the data is filtered but the appropriate checkbox adjacent to the "False" value in the filter is not checked.

Here is a snippet of the code that resides within the GridLoaded event of my ViewModel.
gridView.FilterDescriptors.SuspendNotifications();
  
GridViewColumn employeeRelatedColumn = gridView.Columns["EmployeeRelatedFlag"];
IColumnFilterDescriptor employeeRelatedFilter = employeeRelatedColumn.ColumnFilterDescriptor;
employeeRelatedFilter.FieldFilter.Filter1.Value = "False";
employeeRelatedFilter.FieldFilter.Filter1.Operator = FilterOperator.IsEqualTo;
  
gridView.FilterDescriptors.ResumeNotifications();
Please advise.

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 09 Oct 2012, 12:07 PM
Hello,

As you would like the item in the Distinct Values list checked, then you have to add a filtering on the DistinctFilter, like so:

employeeRelatedFilter.DistinctFilter.AddDistinctValue("False");

You can refer to our online documentation. I hope this helps.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Deon
Top achievements
Rank 1
answered on 10 Oct 2012, 03:27 AM
Hi Didie,

I had tried that earlier without success.

The code currently looks like this:

gridView.FilterDescriptors.SuspendNotifications();
   
GridViewColumn employeeRelatedColumn = gridView.Columns["EmployeeRelatedFlag"];
IColumnFilterDescriptor employeeRelatedFilter = employeeRelatedColumn.ColumnFilterDescriptor;
 
employeeRelatedFilter.DistinctFilter.AddDistinctValue("False");
employeeRelatedFilter.DistinctFilter.AddDistinctValue("True");
 
employeeRelatedFilter.FieldFilter.Filter1.Value = "False";
employeeRelatedFilter.FieldFilter.Filter1.Operator = FilterOperator.IsEqualTo;
   
gridView.FilterDescriptors.ResumeNotifications();


The result is the same - the filter icon is highlighted and the grid is filtered as expected (rows with a value of "True" are excluded and those with a value of "False" are included.)  However, the filter still does not indicate that "False" is checked. 

Furthermore, the behavior of the filter is incorrect (when checking the checkboxes) until the "Clear Filter" button is clicked.

The documentation demonstrates with Country names which are strings and in my attempt to reproduce that, the checkboxes are not set either.  In that case, the value is placed in the filter1 or filter2 textbox with that appropriate operator.

In my case, I have a column with a Boolean value, being displayed in a checkbox column.  Is there something else that I would need to do in this scenario?


0
Accepted
Rossen Hristov
Telerik team
answered on 10 Oct 2012, 08:10 AM
Hello,

Boolean columns do not show their Field Filters. There is no point in setting anything on them. Distinct values are on top in a list box. Field Filters are on bottom and are two. The boolean column shows only its distinct values, since they are only two and are everything that you need for filtering.

The following code makes no sense:
employeeRelatedFilter.DistinctFilter.AddDistinctValue("False");
  
employeeRelatedFilter.DistinctFilter.AddDistinctValue("True");
  
  
  
employeeRelatedFilter.FieldFilter.Filter1.Value = "False";
  
employeeRelatedFilter.FieldFilter.Filter1.Operator = FilterOperator.IsEqualTo;

You are telling the grid the following:

Please, give me all records that (are "True" OR are "False") AND are "False".

The thing in the parenthesis is the expression generated by the distinct values that you have added. The thing after the AND is the expression generated from the field filter that you have defined.

Since the column is boolean, the two distinct values "True" and "False" are not valid. The "False" that you add to the field filter (which is invisible in boolean columns) is smartly converted by WPF Binding to the boolean false and you still get the filtering being done on the grid. That is why you see the grid filtered. But you should not touch the field filter.

Booleans are not strings. Do not use strings instead of booleans. They are not interchangeable in the .NET Framework.

In the .NET Framework, "True" is a string. On the other hand true is a boolean. Same applies for "False' and false.

In case your column is boolean, the only thing you need to do is add a boolean value, not a string. Every boolean column can have only two valid distinct values -- true and false. If you add true as a distinct value, you will get all records that are true. If you add false as a distinct value, you will get all records that are false. If you add them both you will get absolutely all records since a boolean can only be true or false.

Also, you do not need to add stuff to the Field Filter. Boolean columns do not display their Field Filters since there is no point in displaying them. The distinct values are enough, since you can not filter on anything different from true or false.

Here is everything that you need to do in order to pre-filter a boolean column:

this.playersGrid.FilterDescriptors.SuspendNotifications();
 
// Add this to get all players that are fit.
this.playersGrid.Columns["IsFit"].ColumnFilterDescriptor.DistinctFilter.AddDistinctValue(true);
 
// Add this to get all players that are NOT fit.
// this.playersGrid.Columns["IsFit"].ColumnFilterDescriptor.DistinctFilter.AddDistinctValue(false);
 
this.playersGrid.FilterDescriptors.ResumeNotifications();

You can also show or hide the Filter button according to your preferences.

I have attached a sample project that does that. Please, check it out.

I hope this helps.

Kind regards,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Deon
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Deon
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or