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

Forums / Developing with Sitefinity / Re-Order RadTree Elemenets

Re-Order RadTree Elemenets

6 posts, 0 answered
  1. James@Nw
    James@Nw avatar
    265 posts
    Registered:
    05 May 2009
    23 Jun 2009
    Link to this post
    Hi Guys,

    Currently the RadTree I am using is displaying the dates from the current year (2009) to the first year (2003). I need it to read in reverse order, so that it reads like this please:

    2003 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009


    How do I do this?

    Thanks,
    James
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Jun 2009
    Link to this post
    Hi James,

    If you are using RatTreeView control there are two options that I could suggest.

    1.Hardcode the items you have.
    2. Crate a sorting for the control :

    Sample code:

    protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                RadTreeview1.DataBind(); 
                SortNodes(RadTreeview1.Nodes); 
            }  
        } 
     
        private void SortNodes(RadTreeNodeCollection collection) 
        { 
            Sort(collection); 
            foreach (RadTreeNode node in collection) 
            { 
                if (node.Nodes.Count > 0) 
                { 
                    SortNodes(node.Nodes); 
                } 
            } 
        } 
     
        //The Sort method is called for each node level sorting the child nodes  
        public void Sort(RadTreeNodeCollection collection) 
        { 
            RadTreeNode[] nodes = new RadTreeNode[collection.Count]; 
            collection.CopyTo(nodes, 0); 
            Array.Sort(nodes, new TreeNodeComparer()); 
            collection.Clear(); 
            collection.AddRange(nodes); 
        } 
     
        //The TreeNodeComparer class defines the sorting criteria  
        class TreeNodeComparer : IComparer 
        { 
            #region IComparer Members 
     
            public int Compare(object x, object y) 
            { 
                RadTreeNode firstNode = (RadTreeNode)x; 
                RadTreeNode secondNode = (RadTreeNode)y; 
                return firstNode.Text.CompareTo(secondNode.Text); 
            } 
            #endregion 
        } 
     
     
                          .... 
                                   ..... 


    Regards,
    Ivan Dimitrov
    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. James@Nw
    James@Nw avatar
    265 posts
    Registered:
    05 May 2009
    23 Jun 2009
    Link to this post
    Hi Ivan...

    Thanks for your reply to this. We're working on the NewsView Control Template for this so is there a way that we can access the C# code for this with your solution or is there another way we can go about this?

    Thanks,
    James
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Jun 2009
    Link to this post
    Hi James,

    Could you tell me the exact control that you are using for displaying the dates? You can also send your implementation and the code declaration you have used. The code I have posted can be used with every RadTreeView control.

    All the best,
    Ivan Dimitrov
    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.
  5. James@Nw
    James@Nw avatar
    265 posts
    Registered:
    05 May 2009
    24 Jun 2009
    Link to this post
    Hi Ivan.

    The control that we are changing at the moment is the NewsView control (the one that you drag out from with Sitefinity onto your page) but we are modifying it using the control template ArchiveTemplate.ascx (which we don't see any C# file for).

    Thanks for getting back to me.

    James
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Jun 2009
    Link to this post
    Hi James,

    I suggest that you should use NewsArchiveControl. Below is implementation that sorts the items in ASC way. Not that the controls caches so that you need to restart the application to see the changes.

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.News.WebControls; 
    using System.Web.UI.WebControls; 
    using Telerik.Cms.Engine.ContentViewFiltering; 
    using System.Collections; 
    using Telerik.Cms.Engine; 
     
    /// <summary> 
    /// Summary description for NewsArchiveControl 
    /// </summary> 
    public class NewsArchiveControl : NewsArchive  
        public NewsArchiveControl() 
        { 
        } 
     
        // the value of the property should be written with space  
        // sample :" DESC" or " ASC" 
        public string SortExpression 
        { 
            get 
            { 
                string obj = (string)this.ViewState["SortExpression"]; 
                if (obj == null
                    return string.Empty; 
                else 
                { 
                    return (string)obj; 
                } 
            } 
            set 
            { 
                this.ViewState["SortExpression"] = value; 
            } 
        } 
       
     
        public override string LayoutTemplatePath 
        { 
            get 
            { 
                return this.layoutTemplatePath ="~/Sitefinity/ControlTemplates/News/ArchiveTemplate.ascx"
            } 
            set 
            { 
                this.layoutTemplatePath = value; 
            } 
        } 
        private string layoutTemplatePath; 
     
        protected override List<Telerik.Cms.Engine.WebControls.ContentArchive.ArchiveItem> GetDates() 
        { 
            IList allContent; 
            List<ArchiveItem> dates = new List<ArchiveItem>(); 
            if (!this.Manager.MetaKeys.ContainsKey(PublicationDateMetaKey) && CustomDataSource == null
            { 
                return dates; 
            } 
            if (CustomDataSource != null
            { 
                allContent = CustomDataSource; 
            } 
            else 
            { 
                string sortExp = String.Concat(PublicationDateMetaKey, SortExpression); 
     
                ContentFilterBuilder filterBuilder = GetFilterBuilder(); 
                filterBuilder.AddFilter(new ContentFilterStatement(PublicationDateMetaKey, "\"" + DateTime.Now.AddDays(1) + "\"", ContentFilter.Condition.LessOrEqual, ContentFilter.JoinType.And)); 
                if (filterBuilder.IsFilterValid) 
                { 
                    allContent = this.Manager.GetContent(0, 0, sortExp, filterBuilder.ParseTagFilter(), 
                                                    ContentStatus.Published, null, filterBuilder.ParseParentsFilter(), 
                                                    filterBuilder.ParseMetaFieldsFilter()); 
                } 
                else 
                { 
                    Literal errorLiteral = new Literal(); 
                    errorLiteral.Text = String.Concat(filterBuilder.FilterErrors.ToArray()); 
                    Controls.AddAt(0, errorLiteral); 
                    return null
                } 
            } 
            int month = 0; 
            int year = 0; 
            int itemsCount = 0; 
            int count = 0; 
     
            foreach (IContent cnt in allContent) 
            { 
                DateTime publicationDate = (DateTime)cnt.GetMetaData(PublicationDateMetaKey); 
                count++; 
     
                if ((month != publicationDate.Month || year != publicationDate.Year) && (month != 0 || year != 0)) 
                { 
                    dates.Add(new ArchiveItem(year, month, itemsCount)); 
                    itemsCount = 1; 
                } 
                else 
                { 
                    itemsCount++; 
                } 
     
                month = publicationDate.Month; 
                year = publicationDate.Year; 
     
                if (count == allContent.Count) 
                { 
                    itemsCount = itemsCount == 0 ? 1 : itemsCount; 
                    dates.Add(new ArchiveItem(year, month, itemsCount)); 
                } 
            } 
     
            return dates; 
        } 
     



    Best wishes,
    Ivan Dimitrov
    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.
Register for webinar
6 posts, 0 answered