Sorting ItemPropertyDefinition.DisplayName

8 posts, 0 answers
  1. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 08 May 2013 Link to this post

    Hi,

    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
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 09 May 2013 Link to this post

    Hello,

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 09 May 2013 Link to this post

    Hi Rossen

    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

  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 10 May 2013 Link to this post

    Hi,

    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.

    Greetings,
    Rossen Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 10 May 2013 Link to this post

    Hi Rossen,

    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
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 13 May 2013 Link to this post

    Hello,

    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.

    Kind regards,
    Rossen Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 13 May 2013 Link to this post

    Hi Rossen,

    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
  9. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 14 May 2013 Link to this post

    Hi,

    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.

    Regards,
    Rossen Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready