The documentation refers to filter descripters in XAML. I've tried to use them, but I can't seem to find the correct namespace:
<
telerikGrid:RadDataGrid
Width
=
"300"
VerticalAlignment
=
"Center"
x:Name
=
"grid"
>
<
telerikGrid:RadDataGrid.FilterDescriptors
>
<
telerikGrid:TextFilterDescriptor
PropertyName
=
"Country"
Operator
=
"StartsWith"
IsCaseSensitive
=
"False"
Value
=
"BR"
/>
</
telerikGrid:RadDataGrid.FilterDescriptors
>
</
telerikGrid:RadDataGrid
>
6 Answers, 1 is accepted
The TextFilterDescriptor class as well as the other types of filter descriptors are located in the Telerik.UI.Xaml.Data.Core namespace. Here is a sample on how to use it:
<
Page
x:Class
=
"UWPgridFD.MainPage"
xmlns:local
=
"using:UWPgridFD"
xmlns:grid
=
"using:Telerik.UI.Xaml.Controls.Grid"
xmlns:core
=
"using:Telerik.Data.Core"
mc:Ignorable
=
"d"
Background
=
"{ThemeResource ApplicationPageBackgroundThemeBrush}"
>
<
Grid
>
<
grid:RadDataGrid
x:Name
=
"DataGrid"
>
<
grid:RadDataGrid.FilterDescriptors
>
<
core:TextFilterDescriptor
PropertyName
=
"Country"
Operator
=
"StartsWith"
IsCaseSensitive
=
"False"
Value
=
"S"
/>
</
grid:RadDataGrid.FilterDescriptors
>
</
grid:RadDataGrid
>
</
Grid
>
</
Page
>
I have attached a sample for your reference. If you have any further questions or concerns, do not hesitate to contact us.
Have a great rest of the week.
Regards,
Stefan Nenchev
Progress Telerik
Thanks.
Although now I can use them, I realise they are not what I need.
I want to be able to make the filter on a column in a grid default to "Contains" and "not case-sensitive", but not with a value as such. I just want these as defaults if the user want to filter a column. Users of the most of the text columns in my grids would always use these options, so it would help a lot if they didn't have to do the extra clicks or taps unnecessarily.
In this case, you can simply leave the Value of the TextFilterDescriptor empty and set the other properties so that your requirements are met. For example:
<
grid:RadDataGrid
x:Name
=
"DataGrid"
>
<
grid:RadDataGrid.FilterDescriptors
>
<
core:TextFilterDescriptor
PropertyName
=
"Country"
Operator
=
"Contains"
IsCaseSensitive
=
"False"
Value
=
""
/>
</
grid:RadDataGrid.FilterDescriptors
>
</
grid:RadDataGrid
>
Once you apply this, you will notice that the default values of the filter descriptor are changed once you open the filtering control.
Regards,
Stefan Nenchev
Progress Telerik
Hi Stefan, I did this originally. It sort of works, but because it applies this filter to the grid contents as soon as the grid is opened, for a text column it specifically excludes rows where the column value is NULL rather than an empty string.
It would be more useful to be able to define defaults for these without the filter itself being pre-defined.
David
Indeed, this would be the case when you have items with null values. Basically, you would need to set a composite filter descriptor which will pass through values with null as well. However, by default the text column uses a TextFilterDescriptor so it would not be possible to achieve the requirement in the way we have previously tried. What you can do is create a custom filtering control as explained in the following article:
- Create Custom Filtering Control
Eventually, in this filtering control, you can add a composite filter descriptor, for example the following one:
CompositeFilterDescriptor cfd =
new
CompositeFilterDescriptor();
cfd.Descriptors.Add(
new
TextFilterDescriptor() { Operator = TextOperator.Contains, IsCaseSensitive =
false
, PropertyName =
"Country"
, Value =
null
});
cfd.Descriptors.Add(
new
TextFilterDescriptor() { Operator = TextOperator.Contains, IsCaseSensitive =
false
, PropertyName =
"Country"
, Value =
""
});
cfd.Operator = LogicalOperator.Or;
Have a great rest of the week.
Regards,
Stefan Nenchev
Progress Telerik