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

Forums / General Discussions / Sorting of Generic Content Items in view

Sorting of Generic Content Items in view

4 posts, 0 answered
  1. Gopinath BR
    Gopinath BR avatar
    5 posts
    Registered:
    05 Nov 2009
    23 Feb 2010
    Link to this post
    Hi,

    I have a few generic content items, listed below as an example -

    1. Content A
    2. Content B
    3. Content C
    4. Content D

    They were entered in the same order as displayed above. When I use the Generic Content View control to display the list, I do not see the order in which it was entered. I tried to provide the below values in SortExpression, but to no use -

    ContentID
    ContentID DESC
    ID
    ID DESC

    Can someone pls help me with the correct SortExpression to be used?

    Regards,
    Gopinath
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Feb 2010
    Link to this post
    Hello Gopinath BR,

    You can sort by metakeys - Name, Author, Category etc or better use DateCreated ASC or DateCreated DESC

    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.
  3. Gopinath BR
    Gopinath BR avatar
    5 posts
    Registered:
    05 Nov 2009
    23 Feb 2010
    Link to this post
    Hello Ivan,

    I tried DateCreated (ASC & DESC), but the list doesnt get sorted. Will sorting on DateCreated also consider the time the content was created? All the content items were created in a matter of few minutes and hence the the DateCreated will be the same for all.

    Is there any way I can sort with an ID?

    Thanks and regards,
    Gopinath,
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Feb 2010
    Link to this post
    Hi Gopinath BR,

    It is not possible to sort by Guid, it is random unique identifier. If you override the control behavior you can do it, but I am not sure what is the idea of sorting Guids, since you do not know the unique identifier value( it is 36 chars). DateCreated works fine at my end using Sitefinity 3.7 SP2, but most probably you are not seeing the result, because the items are created within short period of time.

    You can sort the list by guid by creating a custom class that Inherits from ContentView. Then override CreateDataSource method. Expose a public property where you set the Guid sorting. If the property value is null(empty) call the base, otherwise create a custom list. To create this custom list you need to call Manager.GetContent() which returns IList of items. Finally use Linq to sorter the list and bind the ContentView control

    sample

    var Manager = new ContentManager("Generic_Content");
    IList list = Manager.GetContent();
    IQueryable<IContent> datasource = ((IList)list).Cast<IContent>().AsQueryable<IContent>();
    datasource.OrderBy(c => c.ID);


    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.
Register for webinar
4 posts, 0 answered