+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Sorting categories

Sorting categories

5 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    25 Oct 2010
    Link to this post
    Hi,

    In a custom module I've developed I have several categories. The client has now specified that they want to be able to sort these categories.

    The categories are:

    - Legal
    - Financial
    - Property

    So there is nothing specific to sort on, but they want to be able to order them in any way they like.

    I can only think of doing this by renaming them:

    1-Legal
    2-Financial
    3-Property

    And then stripping the number on the public part of thw website. Is there a better way?

    Regards,
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Oct 2010
    Link to this post
    Hello Alastair,

    You can use LINQ to sort the categories by any property that the data object (ICategory or your custom one) expose.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    25 Oct 2010
    Link to this post
    Hi Ivan,

    How would I acheieve that with this code?

    //return list of categories
    private IList<ICategory> GetCategoryDataSource() {
         
        var cntManager = new ContentManager(CaseStudyManager.DefaultContentProvider);
        IList allCategories = cntManager.GetCategories();
        List<ICategory> filteredList = new List<ICategory>();
        foreach (ICategory category in allCategories) {
     
            filteredList.Add(category);
     
        }
        return filteredList;
    }

    Im not sure what I should be comparing to?

    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Oct 2010
    Link to this post
    Hello Alastair,

    This code does not do anything more that returning a list of categories. First you need to define which parameter you will use for sorting/filtering and the create the list of items that will be returned by your method.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    25 Oct 2010
    Link to this post
    Ivan,

    I realise my code does nothing more than returning the list of categories - that's my original code that does not sort.

    Do you have a code example, im not sure how the .Sort() interfaces with ICategory?

    Thanks
    higgsy


Register for webinar
5 posts, 0 answered