Is there a nice way to have all my string columns have a filter IsNullOrWhitespace ?
11 Answers, 1 is accepted
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.
So how I can intercept the users filter request and modify it?
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.
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.
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.
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.
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.
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.
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.