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

Issue with Filters when added programmatically

5 Answers 264 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Mohammed asked on 05 Aug 2016, 10:24 AM

I have a requirement to add a default filter to the my GridView.  Therefore I do this simply using the following code:

            FilterDescriptor filterDescriptor = new FilterDescriptor();
            filterDescriptor.PropertyName = "DistributionStatus";
            filterDescriptor.Value = "Active";
            filterDescriptor.Operator = FilterOperator.IsNotEqualTo;
            filterDescriptor.IsFilterEditor = true;

This is simply code taken from the documentation and modified.

This applies the restriction that I require, but when I open up the filter on screen as a user, I do not see all the values available in the column, so I am unable to remove this filter... Please see attached file (1.png) for an example.

If however, I add a random filter that does not affect the results (2.png), I now see all my available options (3.png).  Can anyone suggest if this is a bug? or maybe a setting I need to update or a forced refresh of some kind?

5 Answers, 1 is accepted

Sort by
0
Mohammed
Top achievements
Rank 1
answered on 08 Aug 2016, 11:15 AM
Telerik, can you confirm if this is a bug please?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Aug 2016, 02:49 PM
Hello Mohammed,

Thank you for writing. 

I would like to note that the basic filtering and the filtering have a difference in their filtering logic. Hence, the applied filter are different. The Excel-Like filtering is designed to perform cascade filtering via the UI and it uses CompositeFilterDescriotors. In order to achieve your requirement, you must apply the following filter: 
FilterDescriptor filterDescriptor = new FilterDescriptor();
filterDescriptor.PropertyName = "Title";
filterDescriptor.Value = "Sales Representative";
filterDescriptor.Operator = FilterOperator.IsNotEqualTo;
 
CompositeFilterDescriptor cfd = new CompositeFilterDescriptor();
cfd.LogicalOperator = FilterLogicalOperator.And;
cfd.FilterDescriptors.Add(filterDescriptor);    
cfd.IsFilterEditor = true;
this.radGridView1.FilterDescriptors.Add(cfd);

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Mohammed
Top achievements
Rank 1
answered on 15 Aug 2016, 10:30 AM

Hi Dess,

Thanks for the reply, but unfortunately, this still causes the same issue.  Here is my code verbatim:

            FilterDescriptor filterDescriptorRemoved = new FilterDescriptor();
            filterDescriptorRemoved.PropertyName = "DistributionStatus";
            filterDescriptorRemoved.Value = "Removed";
            filterDescriptorRemoved.Operator = FilterOperator.IsNotEqualTo;

            CompositeFilterDescriptor cfd = new CompositeFilterDescriptor();
            cfd.LogicalOperator = FilterLogicalOperator.And;
            cfd.FilterDescriptors.Add(filterDescriptorRemoved);
            cfd.IsFilterEditor = true;

            radGrdVwBookings.FilterDescriptors.Add(cfd);

It seems this creates a custom filter, which removes the valid selections from the list.  In this case I only see the 'Active' value which is checked... I would expect to see:

Active - Checked
Removed - Not Checked

Instead I just see 

Active - Checked (See 4.png)

Therefore have no option to include the 'Removed' rows.

I have found that the Clear Filter option (see arrow on 4.png) resets the values and the 'Removed' value then appears... it is a work around, but suspect users will be confused by this and at a glance simply assume there are no 'Removed' entries in the grid.

Is there any other way of creating filters so all valid values appear, but only certain ones are checked?

Thanks

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Aug 2016, 08:46 AM
Hello Mohammed, 

Thank you for writing back. 

I have missed to include in the code snippet from my previous post a very important code line specifying the ExcelFilteredColumns
FilterDescriptor filterDescriptor = new FilterDescriptor();
filterDescriptor.PropertyName = "Title";
filterDescriptor.Value = "Sales Representative";
filterDescriptor.Operator = FilterOperator.IsNotEqualTo;
 
CompositeFilterDescriptor cfd = new CompositeFilterDescriptor();
cfd.LogicalOperator = FilterLogicalOperator.And;
cfd.FilterDescriptors.Add(filterDescriptor);    
cfd.IsFilterEditor = true;
this.radGridView1.FilterDescriptors.Add(cfd);
 
this.radGridView1.MasterTemplate.ExcelFilteredColumns.Add(this.radGridView1.Columns["Title"]);

Now, you are supposed to achieve the desired result. I have attached my sample project for your reference.

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Mohammed
Top achievements
Rank 1
answered on 16 Aug 2016, 11:59 AM

Thank you Dess!  The last line did the trick!

Issue resolved... Thanks again!

Tags
GridView
Asked by
Mohammed
Top achievements
Rank 1
Answers by
Mohammed
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or