More in this section

Forums / Developing with Sitefinity / NewView SortExpression

NewView SortExpression

6 posts, 0 answered
  1. Brendan
    Brendan avatar
    5 posts
    Registered:
    01 May 2008
    03 Feb 2009
    Link to this post
    I have a newsview in a particular page. That newsview displays items based on specific tagid. The items appear, but the sort appears to be random, despite the Setting: Advanced->Filters->SortExpression: Publication_Date DESC.

    Am I am in the wrong place? I've seen instructions posted previously to sort unde the "Appearance" section in, but I see no sort option in the section.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Feb 2009
    Link to this post
    Hello Brendan,

    Thank you for using our services.

    In Sitefinity 3.5 SP1 you can sort your news under AdvancedTab, Filters, Sort expression. To Filter news by tag and sort them you should have the following
    FilterExpression: Publication_Date <= "#now" AND Expiration_Date > "#now" AND Tag.Name = "YOUR TAG NAME HERE"
    SortExpression: Publication_Date DESC

    Let us know if you need further assistance.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    21 Oct 2009
    Link to this post
    Hi team,

    I can´t get sortexpression in newsview or contentview class in new v37. Could you explian where add the sort expression programatically for one newsview. As filter? 

    Regards.
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    21 Oct 2009
    Link to this post
    Hi Pierre,

    Thank you for using our services.

    There should be no problem with setting sort expressions and filter expressions in the designer of the built in content view controls. I have tested this in the latest version of Sitefinity and it worked as expected. Anyway in order to set them through code you can create a custom control that will inherit for that news view and build filter expressions there. Consider the sample code bellow:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Framework.Web.Design;
    using Telerik.News.WebControls;
    using System.Collections;
    using Telerik.Cms.Engine.ContentViewFiltering;
    using System.Web.UI.WebControls;
    using Telerik.News;
     
    namespace Telerik.Samples
    {
        /// <summary>
        /// Summary description for CustomNews
        /// </summary>
        [ControlDesigner("Telerik.Samples.Design.CustomNewsDesigner, App_Code")]
        public class CustomNews : NewsView
        {
            public CustomNews()
            {
                //
                // TODO: Add constructor logic here
                //
            }
            public override string ItemListTemplatePath
            {
                get
                {
                 //Provide the path to your News Items List template
                    return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx";
                }
                set
                {
                    base.ItemListTemplatePath = value;
                }
            }
     
            public override string SingleItemTemplatePath
            {
                get
                {
                 //Provide the path to your Single News Item template
                    return "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx";
                }
                set
                {
                    base.SingleItemTemplatePath = value;
                }
            }
     
            //this function creates to content lists based on some filters and then merges them
            protected override IList CreateDataSource()
            {
                NewsManager man = new NewsManager("News");
                ContentFilterBuilder filterBuilder1 = new ContentFilterBuilder(this);
                //Define your filter
                filterBuilder1.AddFilter(new ContentFilterStatement("Tag.Name", "Title...", ContentFilter.Condition.Equal, ContentFilter.JoinType.And));
                if (filterBuilder1.IsFilterValid)
                    //You can also build filters for categories and tags
                    //however than you will have to use filterBuilder1.ParseCategories() or filterBuilder1.ParseTagsFilter etc
                    return man.Content.GetContent(filterBuilder1.ParseMetaFieldsFilter());
            }                
        }     
    }

    Then you should add this custom control to the toolbox of your website, using the following web.config line:
    <toolboxControls>
            <clear />
            ...
            <add name="News View" section="Custom Controls" type="Telerik.Samples.CustomNews, App_Code"/>
    </toolboxControls>


    Regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    21 Oct 2009
    Link to this post
    Hi Radoslav,

    These expresions are perfect for filter but what´s about sorting. Could you add one expression for sorting in newsview?. I have tried adding this.filterExpression = "Order Desc" but result is not sorted.
    Thanks.
  6. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    21 Oct 2009
    Link to this post
    Hi,

    Ok, Fired. We can use SortExpression from ContentBasic class  and override CreateContentList() in newsview adding this.SortExpression.

    Thanks, regards
Register for webinar
6 posts, 0 answered