This is a migrated thread and some comments may be shown as answers.

Sortng the Groups with a different order

7 Answers 146 Views
JumpList
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Edouard
Top achievements
Rank 1
Edouard asked on 04 Mar 2011, 11:23 AM
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,

7 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 09 Mar 2011, 12:58 PM
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>>
0
Edouard
Top achievements
Rank 1
answered on 09 Mar 2011, 01:09 PM
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,
0
Accepted
Deyan
Telerik team
answered on 09 Mar 2011, 03:33 PM
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>>
0
Edouard
Top achievements
Rank 1
answered on 10 Mar 2011, 03:54 PM
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,
0
Deyan
Telerik team
answered on 16 Mar 2011, 05:23 PM
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>>
0
Edouard
Top achievements
Rank 1
answered on 16 Mar 2011, 07:53 PM
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,
0
Deyan
Telerik team
answered on 22 Mar 2011, 03:32 PM
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>>
Tags
JumpList
Asked by
Edouard
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Edouard
Top achievements
Rank 1
Share this question
or