Sortng the Groups with a different order

8 posts, 1 answers
  1. Edouard
    Edouard avatar
    17 posts
    Member since:
    Feb 2011

    Posted 04 Mar 2011 Link to this post

    Hi,

    I'm grouping my items by categories, but I want to sort the categories with an index, and display the category name in the GroupHeaderTemplate.

    I don't know how to do that with the RadJumpList ?

    Thanks,
  2. Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 09 Mar 2011 Link to this post

    Hi Edouard,

    Thanks for contacting us and for your question.

    I am not quite sure that I correctly understand your scenario and therefore would like to ask you to give me some further details on the case.

    In general, you can group and then sort the groups, or first sort the items and group them so that the content of the groups is sorted. However, I would like to receive some further details on your case in order to be able to help.

    Thanks for your time.

    Best wishes,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
  4. Edouard
    Edouard avatar
    17 posts
    Member since:
    Feb 2011

    Posted 09 Mar 2011 Link to this post

    Thanks for your answer.

    To explain my case easier, we can suppose that I have three categories, A, B and C, but I want to show them (and their items) in another order, for example : B, C and A.

    The only solution I thought is to use a specific class with at least two properties : the Index I want (0 for B, 1 for C and 2 for A) and the Label of the category. I've implemented the IComparable interface and the following methods :
    public int CompareTo(object obj);
    public override bool Equals(object obj);
    CompareTo uses a comparison between the Index Properties.
    I used this class in the GenericGroupDescriptor.

    But it's not sorting the items in the order I want.

    One more thing, if I edit the two templates (GroupTemplate and GroupPickerItemTemplate) and change the Text Property of the TextBlock (by default : {Binding}, which shows me the name of my specific class), nothing appears in the TextBlock.

    Thanks,
  5. Answer
    Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 09 Mar 2011 Link to this post

    Hello Edouard,

    Thanks for writing back and for the requested details.

    You can implement this scenario by first sorting your list based on the property you would like to define the order of the groups. After that you should perform grouping with SortMode None for the group descriptors.

    Let me know if this works for you.

    Greetings,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  6. Edouard
    Edouard avatar
    17 posts
    Member since:
    Feb 2011

    Posted 10 Mar 2011 Link to this post

    Hello,

    Thanks for your answer, with three Descriptors (one SortDescriptor, one GroupDescriptor and finally one SortDescriptor) it works great.

    I've one more question.

    How can I use several properties of my class in the GroupTemplate and the GroupPickerItemTemplate ? For example, how to show one text and one image (depending of the group) in these templates ?

    If I use a custom class in one GenericGroupDescriptor, Binding to one custom property doesn't display anything.

    Tell me if you prefer that I create a new subject, even if it's linked with the first one.

    Thanks,
  7. Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 16 Mar 2011 Link to this post

    Hello Edouard,

    Thanks for writing back and sorry for the delay with my answer.

    Currently the behavior that you would like to achieve is possible but you will have to write some code.

    In general, you will have to instruct the RadJumpList to group by a key that basically is your business object. You will also have to override the Equals method and provide custom comparison within your business object that is based on the property you would like to actually group by. In this way, the content of the group headers will be your business object itself thus enabling you to visualize any public property you have defined on it.

    Since the approach is not straightforward we will consider simplifying it in future releases but I cannot give you an exact timeframe when this will happen.

    I hope this helps.

    All the best,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  8. Edouard
    Edouard avatar
    17 posts
    Member since:
    Feb 2011

    Posted 16 Mar 2011 Link to this post

    Hello Deyan,

    Thanks a lot for your answer. I've some questions :
    - when you tell "instruct the RadJumpList to group by a key that basically is your business object", do you mean to use the
    RadJumpList.GroupDescriptors.Add(new GenericGroupDescriptor<TElement, TKey>(Func<TElement, TKey> keySelector) or another way ?
    - which methods are necessary to implement the custom comparison ? If I implement the IComparable interface, is it enough, or do I need to implement something else ?

    EDIT : I finally understood what was wrong in my Binding : I wrote {Binding propertyName} instead of {Binding Key.propertyName}. Now it works great. Thanks again for your help.

    Thanks,
  9. Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 22 Mar 2011 Link to this post

    Hi Edouard,

    Thanks for writing back and sorry for the delay with my answer.

    Here is a code snippet of the approach I am talking about:

    private void BindListBox()
    {
        List<MyBusinessObject> source = new List<MyBusinessObject>();
        for (int i = 0; i < 100; i++)
        {
            MyBusinessObject myObj = new MyBusinessObject();
            myObj.Age = i % 2 == 0 ? 20 : 25;
            myObj.Name = "My Name" + i;
            source.Add(myObj);
        }
        this.jumpList.ItemsSource = source;
        GenericGroupDescriptor<MyBusinessObject, MyBusinessObject> descriptor = new GenericGroupDescriptor<MyBusinessObject, MyBusinessObject>(
            (obj) =>
            {
                return obj;
            });
        this.jumpList.GroupDescriptors.Add(descriptor);
    }
    public class MyBusinessObject : IComparable<MyBusinessObject>
    {
        public string Name
        {
            get;
            set;
        }
        public int Age
        {
            get;
            set;
        }
        public override bool Equals(object obj)
        {
            return this.Age == (obj as MyBusinessObject).Age;
        }
        public override int GetHashCode()
        {
            return this.Age;
        }
        public int CompareTo(MyBusinessObject other)
        {
            return this.Age.CompareTo(other.Age);
        }
    }

    Basically, I have my business object in which I am overriding the GetHashCode, Equals methods, and also implement the IComparable interface. Age is the property I would like to group by and therefore I use it when implementing the IComparable interface and the overriden methods to distinguish between the separate objects. I also create a GenericGroupDescriptor which returns the data object itself as the group by key.

    I hope this helps.

    Do not hesitate to get back to me in case you need further assistance on this.

    All the best,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top
DevCraft banner