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

Forums / General Discussions / Sorting issue in admin event module

Sorting issue in admin event module

2 posts, 0 answered
  1. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    22 Oct 2010
    Link to this post
    I have added a column, event start date, to the Admin Events Module  (sitefinity/admin/controltemplates/events/EventsItemsList.ascx).  The event list is sorted by publish date by default. How can I make the list sorted by event start date in ascending order? Below is the code for the EventsItemsList.ascx control. thanks.

    <%@ Control Language="C#" %>
    <telerik:jsfilelink id="jsLink" runat="server" scripttype="jQuery"></telerik:jsfilelink>
    <div style="display: none;">
        <asp:TextBox ID="FilterExpressionField" runat="server"></asp:TextBox>
    </div>
    <div class="ToolsAll">
        <asp:HyperLink ID="createNewButton" runat="server" CssClass="CmsButLeft new">
            <strong class="CmsButRight light">
                <asp:Literal ID="createNewButtonText" runat="server" />
            </strong>
        </asp:HyperLink>
        <div class="groupEdit">
            <asp:LinkButton ID="groupOperationsLink" runat="server" CssClass="groupEditExpand"
                OnClientClick="groupOpsVisible = ToggleDiv('groupOperationsDiv'); return false;">
                <asp:Literal ID="litButton1" runat="server" Text="<%$Resources:GroupOperations %>"></asp:Literal>
            </asp:LinkButton>
            <div id="groupOperationsDiv" style="display: none;">
                <div class="groupActionsPopup">
                    <span class="numberOfSelectedItem"><strong id="numberOfSelectedItems">0</strong><asp:Literal
                        ID="lblSelectedItems" runat="server" Text="<%$Resources:ItemsSelected %>"></asp:Literal></span>
                    <ul>
                        <li><span id="disabledDeleteGroupGrid" class="disabled">
                            <asp:Literal ID="Literal20" runat="server" Text="<%$Resources:Delete %>"></asp:Literal></span>
                            <asp:LinkButton Style="display: none;" ID="btnDeleteGroupGrid" runat="server" OnClientClick="DeleteWithConfirmation(); return false;"
                                Text="<%$Resources:Delete %>"></asp:LinkButton>
                            <asp:Literal ID="lblSelected" runat="server" Text="<%$Resources:Selected %>" />
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <asp:PlaceHolder ID="fullWindow" runat="server">
            <div class="searchItems">
                <div class="searchInputs">
                    <asp:Label ID="Label1" AssociatedControlID="searchField" Text="<%$Resources:SearchEventsBy %>"
                        runat="server"></asp:Label>
                    <asp:DropDownList ID="searchField" runat="server">
                    </asp:DropDownList>
                    <asp:Label ID="Label2" AssociatedControlID="searchWords" Text="<%$Resources:For %>"
                        runat="server"></asp:Label>
                    <asp:TextBox ID="searchWords" CssClass="searchString" runat="server"></asp:TextBox>
                    <asp:Button ID="searchButton" Text="<%$Resources:Search %>" runat="server" CssClass="searchButton" />
                </div>
            </div>
        </asp:PlaceHolder>
        <div class="clear">
            <!-- -->
        </div>
    </div>
    <div class="workArea multipleItemView">
        <telerik:messagecontrol runat="server" id="message">
        <ItemTemplate>
            <asp:Label runat="server" ID="messageText"></asp:Label>
        </ItemTemplate>
        </telerik:messagecontrol>
        <div class="listHeader moduleItemsHeader">
            <h2 class="gridTitle">
                <asp:Label runat="server" ID="title">
                    <asp:Literal ID="Literal2" runat="server" Text="<%$Resources:AllEvents %>" /></asp:Label></h2>
        </div>
        <div class="viewOptions">
            <p>
                View as:
                <asp:HyperLink ID="listViewCommand" runat="server" Text="<%$Resources:ListView %>"
                    CssClass="sfSel"></asp:HyperLink>
                |
                <asp:HyperLink ID="schedulerViewCommand" runat="server" Text="<%$Resources:SchedulerView %>"></asp:HyperLink></p>
        </div>
        <telerik:clienttemplatesholder id="GridTemplates" runat="server">
            <telerik:ClientTemplate Name="Edit" runat="server">
                <a href="<%= ((Telerik.Events.WebControls.Admin.EventsItemsList)Parent.Parent).ItemEditUrl %>"><asp:Literal ID="Literal7" Text="<%$ Resources:Edit %>" runat="server" /></a>
            </telerik:ClientTemplate>
            <telerik:ClientTemplate Name="Delete" runat="server">
                <a href="javascript:if(confirm('<%= GetLocalResourceObject("AreYouSure_Delete") %>')) DeleteContent('{#ID#}')"><asp:Literal ID="Literal1" Text="<%$ Resources:Delete %>" runat="server" /></a>
            </telerik:ClientTemplate>
            <telerik:ClientTemplate Name="View" runat="server">
                <a href="<%= ((Telerik.Events.WebControls.Admin.EventsItemsList)Parent.Parent).ItemViewUrl %>">{#MetaFields.Title#}</a>
            </telerik:ClientTemplate>
            <telerik:ClientTemplate Name="Title" runat="server">
                {#MetaFields.Title#}
            </telerik:ClientTemplate>
               <telerik:ClientTemplate Name="Event_Start" runat="server">
                {#MetaFields.Event_Start#}
            </telerik:ClientTemplate>
            <telerik:ClientTemplate Name="Status" runat="server">
                {#Status#}
            </telerik:ClientTemplate>
        </telerik:clienttemplatesholder>
        <div id="gridPlaceholder">
            <telerik:radgrid id="ItemsGrid" runat="server" autogeneratecolumns="false" allowsorting="true"
                allowpaging="true" pagesize="50" enableviewstate="false" skin="SitefinityItems"
                enableembeddedskins="false" allowmultirowselection="true">
            <MasterTableView AllowMultiColumnSorting="true" CssClass="listItems listItemsBindOnClient" Width="98%">
                <Columns>
                    <telerik:GridTemplateColumn UniqueName="Edit" ItemStyle-CssClass="gridActions edit" />
                    <telerik:GridTemplateColumn UniqueName="Delete" ItemStyle-CssClass="gridActions delete" />
                    <telerik:GridClientSelectColumn UniqueName="CheckBoxColumn" HeaderStyle-CssClass="check" ItemStyle-CssClass="check">
                    </telerik:GridClientSelectColumn>
                    <telerik:GridTemplateColumn
                        UniqueName="View"
                        SortExpression="Title"
                        ItemStyle-CssClass="gridContentTitle"
                        HeaderText="<%$ Resources:Title %>">
                    </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn
                        UniqueName="Event_Start"
                        HeaderText="Event Start">
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn
                        UniqueName="Status"
                        HeaderText="<%$ Resources:Status %>">
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
            <PagerStyle Mode="NumericPages" />
            <ClientSettings>
                <ClientEvents OnCommand="RadGrid_Command" OnRowDataBound="RadGrid_RowDataBound" OnRowSelected="RadGrid_RowSelected" OnRowDeselected="RadGrid_RowDeselected" />
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
        </telerik:radgrid>
        </div>
        <asp:HiddenField ID="cultureInfoField" runat="server" />
        <telerik:radcodeblock id="RadCodeBlock1" runat="server">
            <script type="text/javascript">
    <!--
                var dataProviderName = "<%= ((Telerik.Events.WebControls.Admin.EventsItemsList)Parent.Parent).ProviderName %>";
                var gridTemplates = ClientTemplates.GetSet("<%= GridTemplates.ClientID %>");
                var allowDelete = "<%= ((Telerik.Events.WebControls.Admin.EventsItemsList)Parent.Parent).AllowDelete %>";
                var allowModify = "<%= ((Telerik.Events.WebControls.Admin.EventsItemsList)Parent.Parent).AllowModify %>";
                var groupOpsVisible = false;
     
                function loadData() {
                    var tableView = $find('<%= ItemsGrid.ClientID %>').get_masterTableView();
                    var currentPageIndex = tableView.get_currentPageIndex();
                    var pageSize = tableView.get_pageSize();
                    var filterExpressionField = document.getElementById('<%= FilterExpressionField.ClientID %>');
                    DataBindGrid(currentPageIndex, pageSize, "", filterExpressionField.value);
                }
                Sys.Application.add_load(loadData);
                function DataBindGrid(currentPageIndex, pageSize, sortExpressionsAsSQL, filterExpressionsAsSQL) {
                    var requiredMetaFields = ['Title', 'Event_Start'];
                    var cultureInfoField = document.getElementById('<%= cultureInfoField.ClientID %>');
                    Telerik.Cms.Engine.Services.ContentService.GetContentItems(currentPageIndex * pageSize, pageSize,
        sortExpressionsAsSQL, filterExpressionsAsSQL, requiredMetaFields, cultureInfoField.value, dataProviderName, updateGrid, OnFailed);
                }
                function RadGrid_Command(sender, args) {
                    args.set_cancel(true);
                    var currentPageIndex = sender.get_masterTableView().get_currentPageIndex();
                    var pageSize = sender.get_masterTableView().get_pageSize();
                    var sortExpressions = sender.get_masterTableView().get_sortExpressions();
                    var filterExpressions = sender.get_masterTableView().get_filterExpressions();
                    if (sortExpressions.length > 0 && filterExpressions.length > 0 && currentPageIndex > 0) {
                        sender.get_masterTableView().set_currentPageIndex(0);
                    }
                    var filterExpressionField = document.getElementById('<%= FilterExpressionField.ClientID %>');
                    var sortExpressionsAsSQL = sortExpressions.toString();
                    var filterExpressionsAsSQL = filterExpressions.toString();
                    if (filterExpressionsAsSQL.length == 0)
                        filterExpressionsAsSQL = filterExpressionField.value;
                    DataBindGrid(currentPageIndex, pageSize, sortExpressionsAsSQL, filterExpressionsAsSQL);
                }
                function updateGrid(result) {
                    var tableView = $find("<%= ItemsGrid.ClientID %>").get_masterTableView();
                    tableView.set_virtualItemCount(result.Count);
                    tableView.set_dataSource(result.Data);
                    tableView.dataBind();
     
                    var emptyWindow = document.getElementById('empty');
                    var gridPlaceholder = document.getElementById('gridPlaceholder');
                    if (result.Count > 0) {
                        emptyWindow.style.display = 'none';
                        gridPlaceholder.style.display = '';
                    }
                    else {
                        emptyWindow.style.display = '';
                        gridPlaceholder.style.display = 'none';
                    }
                }
                function RadGrid_RowSelected(sender, args) {
     
                    var dataItem = args.get_gridDataItem();
                    var insertNewID = true;
                    var currentCount = parseInt(document.getElementById("numberOfSelectedItems").innerHTML);
                    if (dataItem._dataItem != null) {
                        for (var i = 0; i < selectedContentIDs.length; i++) {
                            if (selectedContentIDs[i] == dataItem._dataItem.ID) {
                                insertNewID = false;
                            }
                        }
                        if (insertNewID) {
                            selectedContentIDs[selectedContentIDs.length] = dataItem._dataItem.ID;
                            currentCount++;
                        }
                    }
                    document.getElementById("numberOfSelectedItems").innerHTML = currentCount.toString();
                    EnableOrDisableGroupOperationButtons(currentCount != 0);
                }
                function RadGrid_RowDeselected(sender, args) {
                    var dataItem = args.get_gridDataItem();
                    var currentCount = parseInt(document.getElementById("numberOfSelectedItems").innerHTML);
                    if (dataItem._dataItem != null) {
                        for (var i = 0; i < selectedContentIDs.length; i++) {
                            if (selectedContentIDs[i] == dataItem._dataItem.ID) {
                                delete selectedContentIDs[i];
                                currentCount--;
                            }
                        }
                    }
                    document.getElementById("numberOfSelectedItems").innerHTML = currentCount.toString();
                    EnableOrDisableGroupOperationButtons(currentCount != 0);
                }
     
                function RadGrid_RowDataBound(sender, args) {
                    var dataItem = args.get_dataItem();
                    var item = args.get_item();
                    var columns = item.get_owner().get_columns();
                    var cells = args.get_item().get_element().cells;
     
                    if (dataItem['IsLocked'] == true) {
                        args.get_item().get_element().className = "cms_locked";
                    }
                    else {
                        args.get_item().get_element().className = "";
                    }
     
                    for (var i = 0; i < cells.length; i++) {
                        var cell = cells[i];
                        var elementName = columns[i].get_element().UniqueName;
                        var html = gridTemplates.Replace(elementName, dataItem);
                        if (html != null)
                            if (html != "") {
                            var date = null;
     
                            if (elementName == 'Event_Start') {
                                date = new Date(dataItem['MetaFields'].Event_Start);
                            }
                            else if (elementName == 'Event_End') {
                                date = new Date(dataItem['MetaFields'].Event_End);
                            }
     
                            if (date && !isNaN(date)) {
                                html = date._toFormattedString('dd MMM yyyy, hh:mm tt', Sys.CultureInfo.CurrentCulture);
                            }
     
                            cell.innerHTML = html;
                        }
                        else {
                            cell.innerHTML = " ";
                        }
                    }
     
                    // disable delete if needed
                    if (dataItem['IsDisabled'] == true || (allowDelete.toLowerCase() == 'false' && dataItem['IsOwner'] == false)) {
                        $(args.get_item().get_element()).children(".delete").children("a").removeAttr("href");
                        $(args.get_item().get_element()).children(".deleteDis").children("a").removeAttr("href");
                        $(args.get_item().get_element()).children(".delete").addClass("deleteDis");
                        $(args.get_item().get_element()).children(".delete").removeClass("delete");
                    }
                    else {
                        $(args.get_item().get_element()).children(".deleteDis").addClass("delete");
                        $(args.get_item().get_element()).children(".deleteDis").removeClass("deleteDis");
                    }
     
                    // disabled edit if needed
                    if (dataItem['IsDisabled'] == true || (allowModify.toLowerCase() == 'false' && dataItem['IsOwner'] == false)) {
                        $(args.get_item().get_element()).children(".edit").children("a").removeAttr("href");
                        $(args.get_item().get_element()).children(".editDis").children("a").removeAttr("href");
                        $(args.get_item().get_element()).children(".edit").addClass("editDis");
                        $(args.get_item().get_element()).children(".edit").removeClass("edit");
                    }
                    else {
                        $(args.get_item().get_element()).children(".editDis").addClass("edit");
                        $(args.get_item().get_element()).children(".editDis").removeClass("editDis");
                    }
                }
     
                function OnFailed(error) {
                    alert("Stack Trace: " + error.get_stackTrace() + "/r/n" +
            "Error: " + error.get_message() + "/r/n" +
            "Status Code: " + error.get_statusCode() + "/r/n" +
            "Exception Type: " + error.get_exceptionType() + "/r/n" +
            "Timed Out: " + error.get_timedOut());
                }
                function DeleteContent(contentId) {
                    Telerik.Cms.Engine.Services.ContentService.DeleteContent(contentId, dataProviderName, DeleteContent_Success, OnFailed);
                }
                function DeleteContent_Success(result) {
                    var tableView = $find('<%= ItemsGrid.ClientID %>').get_masterTableView();
                    var currentPageIndex = tableView.get_currentPageIndex();
                    var pageSize = tableView.get_pageSize();
                    var sortExpression = tableView.get_sortExpressions();
                    var filterExpressionField = document.getElementById('<%= FilterExpressionField.ClientID %>');
                    var sortExpressionAsSQL = sortExpression.toString();
                    var filterExpressionAsSQL = filterExpressionField.value.toString();
                    tableView.clearSelectedItems();
                    DataBindGrid(currentPageIndex, pageSize, sortExpressionAsSQL, filterExpressionAsSQL);
                }
     
                var selectedContentIDs = [];
     
                function DeleteSelectedContent() {
                    var guidsToPass = [];
                    for (var i = 0; i < selectedContentIDs.length; i++) {
                        if (selectedContentIDs[i] != undefined) {
                            guidsToPass[guidsToPass.length] = selectedContentIDs[i];
                        }
                    }
                    Telerik.Cms.Engine.Services.ContentService.GroupDeleteContent(guidsToPass, dataProviderName, DeleteContent_Success, OnFailed);
                    ToggleDiv('groupOperationsDiv');
                }
     
                function DeleteWithConfirmation() {
                    if (confirm('<%= GetLocalResourceObject("AreYouSure") %>')) DeleteSelectedContent();
                }
     
                function EnableOrDisableGroupOperationButtons(enable) {
                    if (enable) {
                        $("#<%= btnDeleteGroupGrid.ClientID %>").show();
                        $("#disabledDeleteGroupGrid").hide();
                    }
                    else {
                        $("#<%= btnDeleteGroupGrid.ClientID %>").hide();
                        $("#disabledDeleteGroupGrid").show();
                    }
                }
     
                function ToggleDiv(divID) {
                    var div = document.getElementById(divID);
                    var result = div.style.display == "block";
                    if (div.style.display != "none") {
                        div.style.display = "none";
                    }
                    else {
                        div.style.display = "block";
                    }
                    return result;
                }
     
                document.onclick = check;
                function check(e) {
                    var target = (e && e.target) || (event && event.srcElement);
                    var obj = document.getElementById('groupOperationsDiv');
                    var obj2 = document.getElementById('<%= groupOperationsLink.ClientID %>');
                    if (groupOpsVisible) {
                        checkParent(target) ? obj.style.display = 'none' : null;
                    }
                    else {
                        checkParent(target) ? obj.style.display = 'none' : null;
                        if (target == obj2) {
                            obj.style.display = 'block';
                        }
                    }
                }
                function checkParent(t) {
                    while (t.parentNode) {
                        if (t == document.getElementById('groupOperationsDiv')) {
                            return false;
                        }
                        t = t.parentNode;
                    }
                    return true;
                }
      
    -->
            </script>
        </telerik:radcodeblock>
        <asp:PlaceHolder ID="emptyWindow" runat="server">
            <div id="empty">
                <h2 class="gridTitle">
                    <asp:Literal ID="Literal3" runat="server" Text="<%$Resources:NoEvents %>" /></h2>
                <p>
                    <asp:HyperLink ID="createNewEmpty" runat="server" CssClass="mainLink" ToolTip="<%$Resources:CreateYourFirstEventTooltip %>">
                        <strong>
                            <asp:Literal ID="Literal4" runat="server" Text="<%$Resources:CreateYourFirstEvent %>" /></strong></asp:HyperLink><br />
                    <asp:Literal ID="Literal5" runat="server" Text="<%$Resources:Or %>" />, <a href="http://www.sitefinity.com/sf3/faq.html#gc"
                        target="_blank" title="Opens in new browser window">
                        <asp:Literal ID="Literal6" runat="server" Text="<%$Resources:CheckEventsFAQ %>" /></a></p>
            </div>
        </asp:PlaceHolder>
    </div>
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    22 Oct 2010
    Link to this post
    Hello Stephen,

    You can modify the DataBindGrid function and pass the condition on which you want to sort the RadGrid as a sortExpressionsAsSQL parameter of GetContentItems web service. You have to change parameter to Event_Start ASC or Event_Start DESC

    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
2 posts, 0 answered