So, when using RadDataFilter in unbound mode, how does the actual filtering get done? I've subscribed to the FilterDescriptor events so I know *when* to do it, but not *how*. Do I need to iterate over the FilterDescriptors and write filtering code myself? I don't see how I can do that, since the only function available on those descriptors is CreateFilterExpression(Expression instance), but I can't find any documentation in the Telerik help on it. What is the instance parameter? Is there a sample that actually demonstrates this?
- Lutz
- Lutz
5 Answers, 1 is accepted
0
Hi Lutz,
In order to filter the data when RadDataFilter is in unbound mode, you have to create the properties you want to show in the drop-down and assign them to ItemPropertyDefinitions. After this is done you have to attach the RadDataFilter's FilterDescriptors to the CollectionChanged event.
In this event when the action is add, you have to insert a FilterDescriptor to the GridView. When you remove a FilterDescriptor from the DataFilter, you have to remove the corresponding GridView FilterDescriptor.
I am attaching a sample project demonstrating this approach.
Regards,
Hristo
Telerik
In order to filter the data when RadDataFilter is in unbound mode, you have to create the properties you want to show in the drop-down and assign them to ItemPropertyDefinitions. After this is done you have to attach the RadDataFilter's FilterDescriptors to the CollectionChanged event.
In this event when the action is add, you have to insert a FilterDescriptor to the GridView. When you remove a FilterDescriptor from the DataFilter, you have to remove the corresponding GridView FilterDescriptor.
I am attaching a sample project demonstrating this approach.
Regards,
Hristo
Telerik
DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.
0
Lutz
Top achievements
Rank 1
answered on 20 Mar 2014, 03:31 PM
Thanks for the reply, but I am not using a RadGridView. I want to use RadDataFilter to filter my list, but the list gets used somewhere else (in a custom user control). In that case, would I need to write my own filtering code that iterates over the FilterDescriptors and does the tests, etc.?
Regards,
- Lutz
Regards,
- Lutz
0
Hello Lutz,
In this case I would recommend to bind the collection to the RadDataFilter's Source property, and to use FilteredSource, as collection for the custom control's Source. That way, the custom control will not have to implement filtering logic, because it will receive the filtered collection.For more details you can check this article. I am also attaching a sample project demonstrating this approach.
Regards,
Hristo
Telerik
In this case I would recommend to bind the collection to the RadDataFilter's Source property, and to use FilteredSource, as collection for the custom control's Source. That way, the custom control will not have to implement filtering logic, because it will receive the filtered collection.For more details you can check this article. I am also attaching a sample project demonstrating this approach.
Regards,
Hristo
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.
0
Grigory
Top achievements
Rank 1
answered on 17 Nov 2014, 03:58 PM
Hello, i'm having same situation. This control is very useful for creating custom filters. In fact i'm trying to use it for creating query expressions to full text engine (e.x. Solr). So I need to convert resulting IFilterDescriptor tree to my own expression tree.
It's not a problem. The problem is to track RadDataFilter descriptor changes. When I attach to CollectionChanged event I can see only add/remove events item from root collection. No event is fired when I change filterdescriptor data. Moreover I need to subscribe to CollectionChanged event on EVERY child CompositeFilter collection.
Finally there is some "strange" code... (so I can wrap this control in my class and use same logic there) But may be there is any other way to achieve same result?
It's not a problem. The problem is to track RadDataFilter descriptor changes. When I attach to CollectionChanged event I can see only add/remove events item from root collection. No event is fired when I change filterdescriptor data. Moreover I need to subscribe to CollectionChanged event on EVERY child CompositeFilter collection.
Finally there is some "strange" code... (so I can wrap this control in my class and use same logic there) But may be there is any other way to achieve same result?
public
MainWindow()
{
InitializeComponent();
ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(
typeof
(RadDataFilter),
new
FilterDescriptorCustomPropertyProvider());
var nameDefinition =
new
ItemPropertyDefinition(
"Name"
,
typeof
(
string
),
"Employee's Name"
);
var nameDefinition2 =
new
ItemPropertyDefinition(
"SomeProperty"
,
typeof
(Value),
"Employee's Name"
);
RadDataFilter.ItemPropertyDefinitions.Add(nameDefinition);
RadDataFilter.ItemPropertyDefinitions.Add(nameDefinition2);
RadDataFilter.FilterDescriptors.CollectionChanged += FilterDescriptors_CollectionChanged;
}
private
void
FilterDescriptors_CollectionChanged(
object
sender, NotifyCollectionChangedEventArgs e)
{
if
(e.NewItems !=
null
)
{
foreach
(var filter
in
e.NewItems.OfType<INotifyPropertyChanged>())
{
filter.PropertyChanged += FilterChanged;
if
(filter
is
CompositeFilterDescriptor)
{
var cFilter = filter
as
CompositeFilterDescriptor;
cFilter.FilterDescriptors.CollectionChanged -= FilterDescriptors_CollectionChanged;
cFilter.FilterDescriptors.CollectionChanged += FilterDescriptors_CollectionChanged;
}
}
}
if
(e.OldItems !=
null
)
{
foreach
(var filter
in
e.OldItems.OfType<INotifyPropertyChanged>())
{
UnsusbscribeFromEvents(filter);
}
}
FilterChanged(
null
,
null
);
}
private
void
FilterChanged(
object
sender, PropertyChangedEventArgs propertyChangedEventArgs)
{
TextBox.Text +=
"Filter changed fired\r\n"
;
}
private
void
UnsusbscribeFromEvents(INotifyPropertyChanged filterDescriptor)
{
if
(filterDescriptor
is
CompositeFilterDescriptor)
{
var cFilterDescriptor = filterDescriptor
as
CompositeFilterDescriptor;
foreach
(var filter
in
cFilterDescriptor.FilterDescriptors.OfType<INotifyPropertyChanged>())
{
UnsusbscribeFromEvents(filter);
}
cFilterDescriptor.FilterDescriptors.CollectionChanged -= FilterDescriptors_CollectionChanged;
}
filterDescriptor.PropertyChanged -= FilterChanged;
}
0
Hi,
Regards,
Dimitrina
Telerik
In that case you could subscribe for the ItemChanged event of RadDataFilter. It will be raised as the user changes the FilterDescriptor's data.
For example:
void
FilterDescriptors_ItemChanged(
object
sender, ItemChangedEventArgs<IFilterDescriptor> e)
{
if
(e.PropertyName ==
"Value"
)
{
// do your stuff
}
...
}
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.