Can I Sort level 2 differently ?

5 posts, 0 answers
  1. Lars Johansen
    Lars Johansen avatar
    31 posts
    Member since:
    Oct 2009

    Posted 10 Jan 2012 Link to this post

    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 
  2. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 10 Jan 2012 Link to this post

    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!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lars Johansen
    Lars Johansen avatar
    31 posts
    Member since:
    Oct 2009

    Posted 11 Jan 2012 Link to this post

    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
  5. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 12 Jan 2012 Link to this post

    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
  6. Lars Johansen
    Lars Johansen avatar
    31 posts
    Member since:
    Oct 2009

    Posted 12 Jan 2012 Link to this post

    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 
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017