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

Filtering Strings with IsEmpty and IsNull

11 Answers 1004 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 05 Dec 2014, 06:58 PM
To most users a null string and an empty string is the same thing.  How can I reflect that in the grid filters?  Right now I have null values that aren't filtered when they select IsEmpty and vice versa. 

Is there a nice way to have all my string columns have a filter IsNullOrWhitespace ?

11 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 10 Dec 2014, 08:26 AM
Hi,

In order to achieve the desired result, you can apply two separate field filter conditions the data to be filtered on. You could define the Filtering criteria as explained in the Programmatic Filtering article. I am afraid there is not an IsNullOrWhitespace operator to suggest though.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dan
Top achievements
Rank 1
answered on 19 Dec 2014, 02:02 PM
Thanks for the reply Dimitrina, the one problem I still find is intercepting the IsEmpty filter and properly replacing it with a composite filter.  I've tried catching the Filtering event and removing the IsEmpty and replacing it, but that didn't seem to work.  Tried the same in the Filtered event, didn't seem to work either. 

So how I can intercept the users filter request and modify it?
0
Dimitrina
Telerik team
answered on 22 Dec 2014, 03:34 PM
Hello,

You cannot change the available IsEmpty option directly, what you can do is to build a condition to filter by both criteria. You can clear the current filtering criteria already defined or keep it and extend it also configuring new criteria for the respective ColumnFilterDescriptor (as illustrated in the article).

Would you please share what have you tried? Would you please also add an image of what the final result you wish to achieve is? 

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dan
Top achievements
Rank 1
answered on 06 Jan 2015, 03:22 PM
So the closest solution I have found so far is on grid.Fitlering, set e.Cancel = true and add a composite filter to the grid.  This actually works, but has a number of drawbacks, one is that any other filters they applied (all be it, stupidly) will disappear. Also, when they open the Filter popup again it looks like no filters are applied and clicking Clear Filters doesn't do anything. To get around that I'll need to implement my own filter control to handle the clear properly.

On Filtering I can catch that the user has requested an IsEmpty filter, and I can add the composite, but there seems to be no way to then remove just the IsEmpty FilterDescriptor.  The collections of Added and Removed don't actually do anything if you modify them, and since the FilterDescriptor is actually just a copy from the backing viewmodel, changing it doesn't actually change the filter. 
So I'm left with "IsEmpty and (IsEmpty or Null)" as the filter criteria on that column.

I understand how to create a composite filter to do what I want, my question is, how do I add that composite filter to the grid in such a way that it is seamless to the user when they click the Filter button.
0
Dan
Top achievements
Rank 1
answered on 06 Jan 2015, 07:02 PM
I understand how to create the composite filter, my question is, how do I added it to the grid in a seamless manner when they click the Filter button?

I've tried catching the Filtering event, looking for IsEmpty and then generating a composite filter, and that almost works.  However the IsEmpty fitler is still there and there seems to be no good way to remove it.  I can add my composite and set e.Cancel = true.  However if they selected "IsEmpty OR IsEqual to 'Blah'" then I'll have to piece that back together by hand which sounds risky. 

I've also played around with inheriting from FilteringControl and injecting myself in the middle of the filter, but it always seems to fall apart with an internal method, or a property with no public setter.
0
Dan
Top achievements
Rank 1
answered on 06 Jan 2015, 07:03 PM
Sorry for the double post, the first one said it failed.
0
Dimitrina
Telerik team
answered on 07 Jan 2015, 06:10 PM
Hello,

You can always attach to the DistinctValuesLoading event of RadGridView and modify the ones that our data engine has calculated. You can also check the Display All Distinct Values article in our documentation for some sample code on using this event. As to defining a custom filtering control, you can find the Custom Filtering Controls article.

In case this doesn't help, may I ask you to try isolating the issue in a demo project illustrating your exact setup and send it to us in a new support ticket? You can also take a look at this blog post for a reference on how to isolate an issue.  

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dan
Top achievements
Rank 1
answered on 19 Jan 2015, 01:26 PM
Any more advice or is this just entirely unsupported?
0
Nick
Telerik team
answered on 22 Jan 2015, 08:49 AM
Hello Dan,

The approach that Dimitrina suggested is one of the ways to go with this. An alternative is to ensure that the null values are represented as string.Empty as well. There are a couple of ways you can do that. The first is to modify the get section in the string property to return string.Empty when the string is null. The second is to use a converter in the Binding which will display string.Empty if a null value is converted. 

Hope this makes sense. 

Regards,
Nick
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dan
Top achievements
Rank 1
answered on 22 Jan 2015, 07:04 PM
Thanks for the reply.  Our app has many grids, we have a behaviour that controls most of our logic and setup generically.  Was hoping for a solution that I could run out of it instead of modifying all my models. 

The converter approach sounded promising but does not appear to work.  It messes up the distinct filters where it shows empty twice, and when I filter by IsEmpty from the drop down, it still doesn't include the one that was null.
0
Boris
Telerik team
answered on 27 Jan 2015, 06:02 PM
Hello Dan,

I am sorry to say that there is no other alternative that we can offer, aside from Nick's suggestions.

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Dan
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Dan
Top achievements
Rank 1
Nick
Telerik team
Boris
Telerik team
Share this question
or