SF 5.1 Lists items sorting [ fix inside ]

Posted by Community Admin on 04-Aug-2018 01:18

SF 5.1 Lists items sorting [ fix inside ]

All Replies

Posted by Community Admin on 14-Sep-2012 00:00

Hi,

If you have the requirement to sort your list items when you display the items in a widget, know that sorting the list items using the toolbar actions ( manually, alphabatically AZ or ZA....) in the backend is meant to persist the sorting and apply it in the Lists Widget.

However, there is a Javascript 
bug that prevents it from working properly in Sitefinity 5.1 SP1 (haven't tried SP2).
Here is a fix i have found to make this work :

1) Add the following class to your Sitefinity project :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
  
namespace SitefinityWebApp.Backend
    using Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.Master;
    using Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.Master.Contracts;
  
    /// <summary>
    /// Overrides the master grid view for ItemsBackendList view.
    /// </summary>
    public class ItemsBackendListMasterGridView : MasterGridView
    
        /// <summary>
        /// Initializes the controls.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="definition">The view definition</param>
        protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container, Telerik.Sitefinity.Web.UI.ContentUI.Contracts.IContentViewDefinition definition)
        
            base.InitializeControls(container, definition);
            var masterViewDefinition = definition as IMasterViewDefinition;
            if (masterViewDefinition != null)
            
                const string ScriptFix = "~/Scripts/Web.Scripts.ListItemsMasterGridViewExtensionsFix.js";
                if (masterViewDefinition.ExternalClientScripts != null && !masterViewDefinition.ExternalClientScripts.ContainsKey(ScriptFix))
                
                    masterViewDefinition.ExternalClientScripts.Add(ScriptFix, "OnMasterViewLoaded");
                        
            
        
    
ScriptFix is the path to a javascript file that will redefine a javascript function set in Sitefinity embedded file.

Telerik.Sitefinity.Modules.Lists.Web.UI.ListItemsMasterGridViewExtensions.prototype._getListsModuleServiceUrl = function (itemsListBase)
    var serviceUrl = itemsListBase.get_serviceBaseUrl();
    serviceUrl = serviceUrl.replace('ListItemService.svc', 'ListsModuleService.svc');
    if (serviceUrl.lastIndexOf('?') != -1)
        serviceUrl = serviceUrl.substr(0, serviceUrl.lastIndexOf('?'));
    
 
    return serviceUrl;


Finally, update the root view node in the configuration file ListsConfig.contentViewControls.ItemsBackend.views.ItemsBackendList.config located in App_Data/Sitefinity/Configuration with the following:
<view xmlns:config="urn:telerik:sitefinity:configuration" xmlns:type="urn:telerik:sitefinity:configuration:type" config:version="5.0.2800.0" viewType="SitefinityWebApp.Backend.ItemsBackendListMasterGridView" viewName="ItemsBackendList">

Notice the extra viewType attribute that contains the path to the new class. 

Voila, by sorting the list items in the backend, you now have sorting persisted and happening in your lists widget as intended.



As a side note, it seems there is the possibility to add external scripts without having to redefine the base MasterGridView with something like :

<view xmlns:config="urn:telerik:sitefinity:configuration" xmlns:type="urn:telerik:sitefinity:configuration:type" config:version="5.0.2800.0" viewName="ItemsBackendList">
    <!-- skipped dialog config -->
    <scripts>
        <script loadMethodName="OnMasterViewLoaded" scriptLocation="~/Scripts/Web.Scripts.ListItemsMasterGridViewExtensionsFix.js" />
    </scripts>
</view>

Unfortunately this doesn't work ( another bug to fix ?)




This thread is closed