Sortorder on queryresult with paging... | Episerver Developer Community

Sortorder on queryresult with paging...

Member since: 2005
 

Hi!

I've a problem when I want to sort my result (latest first...) from a query using QyeryHandler and also using paging on the result. The result-collection is divided on each page in the paging with the latest created record on the last page. If I then use the Sort()-method on the collection, each page in the paging is just sorted... The last created record is still on the last page... but on top of that.

There is no overload for the QueryHandler.GetQueryResult()-method that takes sortorder-parameter.

EntryCollection entries = QueryHandler.GetQueryResult<Entry, EntryCollection>(q, EPiServer.Templates.RelatePlus.Utils.CacheTimeOut.Search, page, ucBlogEntries.PageSize, out totalItems);

entries.Sort(new DateComparer());

Any ideas of how to sort the query-result and still keep the paging?

Best regards
Marcus

#29843 May 19, 2009 9:29
  • Member since: 2007
     

    Hi Marcus,

    The idea with all of the Get-methods and also with the Query system in EPiServer Community is that you let the database to the sorting for you.

    In the query case you will see that all of the Query objects will have a property called OrderBy. In case of ImageGallery it could look something like this:

    ImageGalleryQuery imageGalleryQuery = new ImageGalleryQuery();

    imageGalleryQuery.LastUpdate = new DateTimeCriterion();

    imageGalleryQuery.OrderBy.Add(new
    CriterionSortOrder(imageGalleryQuery.LastUpdate,
    SortingDirection.Descending));

    Note that you have to init the criterion that you want to sort on.

    Best regards,
    Tom Stenius

    #29876 May 19, 2009 21:10
  • Member since: 2005
     

    Thanks!

    It worked fine.

    Best regards
    Marcus

    #29890 May 20, 2009 11:15
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
Please login to post a reply