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

Forums / Developing with Sitefinity / Custom sort field for manual sorting

Custom sort field for manual sorting

10 posts, 0 answered
  1. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    28 Sep 2010
    Link to this post
    Are there any ideas on creating a way for an admin to set the sort order for a list of documents in a library?
    I have tried this: creating a custom field where they can enter a number for the order.
    However, there may be 3 out of the 10 files they want listed on top then the rest ordered by their Name.

    I followed all instructions for changes in webconfig and maping of templates.  I have made the custom filed an integer and also tried short text. Not sure which is a better solution. 
    I am using the LibraryItemList.ascx for the Admin view of the list, LibraryItemEdit.ascx for the item edit view, and DownlistListTableMode.ascx for the front end view.
    Also, how do i sort the listing of the documents in the admin side (LibraryItemList.ascx ) to be the Custom Field "SortOrder" first then if blank (actually it says 'undefined'), finish sorting by the Name of the document.  In addition, sometimes (every third click of hte column heading) when clicking on the Sort Order column in the grid, the rows with 'undefined' fields disappear!

    Thank you.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    28 Sep 2010
    Link to this post
    Hello Laura,

    Inside library item list there is a function DataBindGrid where you have to add your custom metakey to the array of  requiredMetaFields. Then we call GetContentItems where you can pass your metakey as sortExpressionsAsSQL to filter the RadGrid. To avoid missing rows when you have not set a value for SortOrder you need to use an empty string  or just set a default value for the SortOrder - for instance "0"


    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
  3. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    28 Sep 2010
    Link to this post
    thank you, i did that and it is working.

    In the client side lisitng such as in the DownloadListTableMode.ascx, is it possible to sort my the metafield and then if there are a remaining list of items with say "0" they are ordered by Title?  Is that possible?  I have read that multiple column sorting is not possible...

    Thank You!
  4. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    28 Sep 2010
    Link to this post
    eh, i thought i got it working... it looked like it because i did a batch edit, but anyhow, how can I control the sort order precedence?  In the Admin side as well as the front end view?  Like order by Sort Order first then if value is "0" order by the Title after all the items with numbers > 0 are listed.   ???
  5. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    28 Sep 2010
    Link to this post
    Since it is a shorttext field, i made the defaut value the text "by title" then it will list the numbered ones first. However I need to have the second sort order by the Title.  I have read that you can't have more than one sort. Is that true? 
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Sep 2010
    Link to this post
    Hello Laura,

    You cannot pass two parameters for SortExpression inside GetContent method and this is the reason why you cannot sort by two parameters. You need a custom web service where you manipulate the list of items with  LINQ and its methods OrderBy, OrderByDescending, OrderBy and ThenBy

    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
  7. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    30 Jan 2011
    Link to this post
    How do I add this custom manual ordering in 4.0? In other words... I suppose I would have to add a custom Sort By field in the drop down list under custom sorting - in a library? 

    Will there ever be a drag and drop type of ordering/re-ordering for a list in a library?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    02 Feb 2011
    Link to this post
    Hello Laura,

    Sitefinity 4.0 allows you to make custom sorting in a library by several parameters. Please check attached screenshot.

    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
  9. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    13 Oct 2011
    Link to this post
    Sorry to bring this thread back to life, but the sort order metafield (or Ordinal as i named it)  will not work if it is text.

    it will not sort correctly. It has to be an integer...  i have changed this to an integer in the web.config and made all empty fields a 0.  The sorting seems to be working now.

    However, when i go to edit, the text box for Sort Order is blank for the 0's and also if i try to update it or update one with a number already in it, it throws this error below so I am obviously missing something here with the textbox in the (**edit to post**) LibraryItemEdit.ascx control.  ???  Thank you!

    Cannot cast System.Int32 to string. The metadata field Ordinal can accept only the following data types: string.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
    Exception Details: System.InvalidCastException: Cannot cast System.Int32 to string. The metadata field Ordinal can accept only the following data types: string.
     
    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
     
    Stack Trace:
     
    [InvalidCastException: Cannot cast System.Int32 to string. The metadata field Ordinal can accept only the following data types: string.]
       Telerik.Cms.Engine.Data.MetaData.ThrowCastException(Object value, String requiredType, String acceptedTypes) +174
       Telerik.Cms.Engine.Data.MetaData.set_Value(Object value) +118
       Telerik.Cms.Engine.Data.ContentVersion.SetMetaDataInternal(Transaction tran, IMetaInfo metaInfo, Object value) +438
       Telerik.Cms.Engine.Data.ContentVersion.SetMetaData(String key, Object value) +108
       Telerik.Cms.Engine.Data.CmsContentBase.SetMetaData(String key, Object value) +22
       Telerik.Cms.Engine.StagedContent.Copy(IContent source, IContent target) +749
       Telerik.Cms.Engine.StagedContent.Publish(IContent content) +13
       Telerik.Cms.Engine.ContentManager.SavedStagedContent(StagedContent staged, ContentStatus status) +230
       Telerik.Cms.Engine.ContentManager.SaveContent(IContent content, ContentStatus status) +1267
       Telerik.Cms.Engine.ContentManager.SaveContent(IContent content) +7
       Telerik.Libraries.WebControls.Admin.LibraryItemEdit.SaveButton_Command(Object sender, CommandEventArgs e) +1187
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +108
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
     
    ________________________________________
    Version Information: Microsoft .NET Framework Version:2.0.50727.4216; ASP.NET Version:2.0.50727.4209
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    13 Oct 2011
    Link to this post
    Hello Laura,

    The metadata field type should be updated in the database.  This is set in [sf_GCMetaData] where you will find a column ValueType.

    If the value is

    0, this means that the type is ShortText
    1, this means that the type is LongText
    2, this means that the type is DateTime
    3, this means that the type is Integer.


    Best wishes,
    Ivan Dimitrov
    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
10 posts, 0 answered