I am creating the ItemPropertyDefinition(s) in code-behind. I add the definitions one at a time based on various user selections peculiar to my app. As I add a ItemPropertyDefinition to the ItemPropertyDefinitions collection, I would like the ItemPropertyDefinition display names to be presented in alphabetical order. Can this be done?
Thanks
Rich
7 Answers, 1 is accepted
When we auto-generate the ItemPropertyDefinitions based on the given Type, we respect the DisplayAttribute.Order property. But since now you are the one adding them -- it is now your job to sort them as you would like.
Greetings,Rossen Hristov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I have written the follow sorting procedure below. This seems to work OK but besides sorting the ItemPropertyDefinitions I would also like to sort the FilterDescriptors. Can you explain how I can access the FilterDescriptor properties in the iinq statement highlighted below. Also could you comment if this is not a good way to do the sorting.
Thanks
Rich
private void SortDataFilter()
{
// Sort and save ItemPropertyDefinitions;
var sortedPropDefs =
from defs in this.WhereFilter.ItemPropertyDefinitions
orderby defs.DisplayName ascending
select defs;
List<ItemPropertyDefinition> sortedPropDefsSave = new List<ItemPropertyDefinition>();
foreach (var x in sortedPropDefs)
sortedPropDefsSave.Add(x);
// Sort and save FilterDescriptors
var sortedFilterDefs =
from defs in this.WhereFilter.FilterDescriptors
// orderby ????????? ascending
select defs;
List<FilterDescriptor> sortedFilterDefsSave = new List<FilterDescriptor>();
foreach (FilterDescriptor x in sortedFilterDefs)
sortedFilterDefsSave.Add(x);
// Clear FilterDescriptors
this.WhereFilter.FilterDescriptors.Clear();
// Clear ItemPropertyDefinitions
this.WhereFilter.ItemPropertyDefinitions.Clear();
// Add sorted ItemPropertyDefinitions back
foreach (var propDef in sortedPropDefsSave)
WhereFilter.ItemPropertyDefinitions.Add(propDef);
// Add FilterDescriptors back
foreach (var filterDef in sortedFilterDefsSave)
WhereFilter.FilterDescriptors.Add(filterDef);
}
#endregion SortDataFilter
I don't really see why you would want to sort the FilterDescriptors -- their order is not important at all. An item either passes the filter or not, so the order of the filter descriptors is not relevant at all.
For example:
var result = customers.Where(c => c.Age > 18 && c.Age < 60)
is exactly the same as
var result = customers.Where(c => c.Age < 60 && c.Age > 18)
So I don't really think that you need to sort the filter descriptors.
Still, if for some reason you want to do that, you can learn more about the filter descriptors API here. The section called Custom Filtering explains what the two different types of FilterDescriptors are and how they are used together. The article is under the RadGridView documentation, but the filter descriptors API is shared between the two controls so they are in fact the same.
Have in mind, that when interacting with RadDataFilter, your end-user can create a hierarchical tree of filter descriptors and not simply a flat one-level list. This hierarchy is explained in the article I mentioned above with diagrams.
I hope this helps.
Rossen Hristov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
You are probably right, I was starting to come to that same conclusion. I was thinking about a situation where there are numerous filters and thought it may be easier to locate a specific filter for change I am aware of the hierarchical tree and plan to add that feature later. I guess that would finish off my filter sorting idea.
I notice that when I have a numeric field filter my program crashes with invalid data. Is there a way or a setting that I can use to have the control stop invalid characters from being entered.
Thanks
Rich
The validation exception that occurs by design when entering invalid characters should be absorbed by the WPF Framework. This exception is needed so the WPF Framework can paint the respective editor in red to indicate there are problems. Are you sure that you are getting an unhandled exception? Maybe the Visual Studio settings are configured to stop at every exception, even if it is handled?
Alternatively, you can always supply your very own custom editor and configure it so it does not accept invalid characters. In fact, you can create any kind of editor that suits your needs as shown in the link above. The only thing you need to remember is to wire your custom editor to our view model by binding its significant property (i.e. Text, SelectedValue, SelectedDate, whatever it produces as an output) to our view model property called Value.
I hope this helps.
Rossen Hristov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Changing the Visual Studio setting did the trick; Thanks.
The control is working almost the way I need it. I would like to be able to change the operator list. For example I would like to add 'Is contained in' for integers. For information a data grid is not involved in this process. I am creating sql SELECT statements dynamically and use the RadDataFilter to help build the WHERE clause. Finally, is it possible to change the operator names.
Thanks
Rich
I am afraid that the list of operators is generated based on the respective Type and while you can remove some of them so the user does not see them, you cannot add new operators which are not inherently supported by the given Type, i.e. the Int32 type does not support the Contains, IsContainedIn, StartsWith, and EndsWith operators since we cannot generate such an expression.
Those operators are available for strings only. If you change the type to string, then these operators will become available.
As for the changing of the names, this could be done via localization.
Rossen Hristov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.