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

Can I Sort level 2 differently ?

4 Answers 86 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Lars Johansen
Top achievements
Rank 1
Lars Johansen asked on 10 Jan 2012, 02:26 PM
Hi 

The documentation shows the treelist sorted by "Name" ASC on all levels
http://www.telerik.com/help/aspnet-ajax/treelist-basic-sorting.html 

How do I sort level 2 by  "Name" DESC ?

Lars Johansen 

4 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 10 Jan 2012, 09:43 PM
Lars:

You can define a different sort criteria for each Node level. Take a look at the Sorting TreeNodes knowledge base article for the server-side code that you can modify to accomplish your requirements.

Hope this helps!
0
Lars Johansen
Top achievements
Rank 1
answered on 11 Jan 2012, 10:39 AM
This time - I'm not going to offer the possiblity to sort via columns to the user.

The plan: Level 1 to have Descending orderby 
and Level > 1 to have Ascending orderby

Looking into http://www.telerik.com/help/aspnet-ajax/treelist-understanding-structure.html
The example have a simple array like this - All Ascending data.

employees.Add(new TestItem("Item0", 0, null));
employees.Add(new TestItem("Item1", 1, 0));
employees.Add(new TestItem("Item2", 2, 1));
employees.Add(new TestItem("Item3", 3, 1));
employees.Add(new TestItem("Item4", 4, null));
employees.Add(new TestItem("Item5", 5, null));
employees.Add(new TestItem("Item6", 6, 5));
employees.Add(new TestItem("Item7", 7, 5));
employees.Add(new TestItem("Item8", 8, 7));
employees.Add(new TestItem("Item9", 9, 7));

Just by changing the array items order I got what i wanted:

employees.Add(new TestItem("Item5", 5, null));
employees.Add(new TestItem("Item4", 4, null));
employees.Add(new TestItem("Item0", 0, null));
employees.Add(new TestItem("Item1", 1, 0));
employees.Add(new TestItem("Item2", 2, 1));
employees.Add(new TestItem("Item3", 3, 1));
employees.Add(new TestItem("Item6", 6, 5));
employees.Add(new TestItem("Item7", 7, 5));
employees.Add(new TestItem("Item8", 8, 7));
employees.Add(new TestItem("Item9", 9, 7));

So the question falls back to Linq - How do I query something like that in Linq ?
Any Linq Expert out there ?

Lars J
0
Tsvetina
Telerik team
answered on 12 Jan 2012, 01:07 PM
Hello Lars,

The apporach for this depends on a few factors, however maybe the most reliable way would be to have two stored procedures - one which queries the database for the "root" records and orders them descending and another one that retrieves and orders the rest of the records in ascending order. Then, in your select statement to retrieve the treelist records, call both an make a union between the returned results.

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Lars Johansen
Top achievements
Rank 1
answered on 12 Jan 2012, 01:29 PM
Hi Tsvetina,

Yes that was also my first idea - but I solved it using a orderby like this:

Level==1 , Level>1 desc

Nice and simple :-)

Thanks Lars 
Tags
TreeList
Asked by
Lars Johansen
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Lars Johansen
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or