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

Forums / Developing with Sitefinity / Sorting by multiple columns (SortExpression)

Sorting by multiple columns (SortExpression)

6 posts, 0 answered
  1. sean2078
    sean2078 avatar
    7 posts
    Registered:
    14 Nov 2004
    03 Jul 2009
    Link to this post
    Hello,

    I have a simple custom module and in it is a custom view class based on Telerik.Cms.Engine.WebControls.ContentView.  I am trying to sort by more than one column at a time.  For example:  "Condition ASC, Capacity ASC, Year ASC".

    When I override SortExpression in my module, I get the error message "Invalid column name" for the 2nd sort term.  If I remove all but the 1st term, all is fine.  If I use the 2nd sort term as the 1st and remove all other terms (just to check to make sure the column name is fine), this works, but I don't get sorting by multiple columns.

    A trace seems to reveal that sorting by more than one column isn't supported by using this method (note the invalid "Capacity" sort expression below:


    exec
     sp_executesql N'SELECT  TOP 10 ''DMetaData;ContentID;LangID;KeyValue;Application;ValueType;ShortText;LongText;DateTimeValue;IntegerValue;FloatValue;GuidValue;Boolean;Binary;Status;CntPrntID;'' AS NN_TABLE_ID_1, T1.[ContentID], T1.[LangID], T1.[KeyValue], T1.[Application], T1.[ValueType], T1.[ShortText], T1.[LongText], T1.[DateTimeValue], T1.[IntegerValue], T1.[FloatValue], T1.[GuidValue], T1.[Boolean], T1.[Binary], T1.[Status], T1.[CntPrntID]
        , ''DContentVersion;Application;ID;LangID;StatusLoc;DateModifiedLoc;DateCreatedLoc;OwnerLoc;'' AS NN_TABLE_ID_2, [dbo].[sf_CmsContentVersion].[Application], [dbo].[sf_CmsContentVersion].[ID], [dbo].[sf_CmsContentVersion].[LangID], [dbo].[sf_CmsContentVersion].[StatusLoc], [dbo].[sf_CmsContentVersion].[DateModifiedLoc], [dbo].[sf_CmsContentVersion].[DateCreatedLoc], [dbo].[sf_CmsContentVersion].[OwnerLoc]
        
        FROM [dbo].[sf_GCMetaData] AS T1 LEFT OUTER JOIN [dbo].[sf_CmsContentVersion] ON (T1.[Application] = [dbo].[sf_CmsContentVersion].[Application] AND T1.[ContentID] = [dbo].[sf_CmsContentVersion].[ID] AND T1.[LangID] = [dbo].[sf_CmsContentVersion].[LangID])  WHERE ( (T1.[Application] = @P_p1 AND [dbo].[sf_CmsContentVersion].[LangID] = @P_p2 AND [dbo].[sf_CmsContentVersion].[StatusLoc] = @P_p3 AND T1.[KeyValue] = ''Condition'' ) ) ORDER BY T1.[ShortText] ASC, Capacity ASC',N'@P_p1 nvarchar(10),@P_p2 int,@P_p3 int',@P_p1=N'/Inventory',@P_p2=127,@P_p3=1


    Can someone please recommend the proper way to accomplish this using SiteFinity?  The tools / API don't seem to support this seemingly basic operation.

    Thank you
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    07 Jul 2009
    Link to this post
    Hi sean2078,

    Unfortunately you are right. The ContentView control does not support multiple column sorting at a time.

    You can do this with the API though. Get all content items with the manager you want, then create a custom comparer to sort the list. The ContentView is bound to an IList of items, so you can do the same when you have your list processed.
    Here is how to get a list of News items for example:
    NewsManager manager = new NewsManager("News"); 
    IList newsItems = manager.Content.GetContent(); 

    As for the native support of your inquiry, we will have that in Sitefinity 4.0 API. We will use LINQ for any content selection or even selection with sorting.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. sean2078
    sean2078 avatar
    7 posts
    Registered:
    14 Nov 2004
    09 Jul 2009
    Link to this post
    Thanks Georgi -

    Really appreciate the response.  Sounds good, that's what I thought - figured I'd check in w/ you guys just to be sure.  Thanks for the update - LINQ should work well for this sort of thing.

    Take care
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    09 Jul 2009
    Link to this post
    Hi sean2078,

    I will be glad to answer all of your further questions. Just let me know if you have some ;)

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  5. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    03 Oct 2011
    Link to this post
    Hi Georgi,

    Can you explain in detail as to how do I go about creating a custom comparer and how do I use it in this situation?

    Thanks,
    Saumitra
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    05 Oct 2011
    Link to this post
    Hello Saumitra,

    Please check the following forum thread - it illustrates the usage of a custom comparer for sorting pages. The same could be applied for content as well.

    All the best,
    Georgi
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested 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
6 posts, 0 answered