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

Forums / Developing with Sitefinity / FilterExpression

FilterExpression

25 posts, 0 answered
  1. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    20 Nov 2008
    Link to this post
    I am using the NewsView and trying to filter out items with the FilterExpression property. I am trying to filter out only those items with a publication date equal to the current date or less than the current date and the expiration date is greater than or equal to the current date. So I set the FilterExpression to:
    Publication_Date <= #Now AND Expiration_Date >= #Now

    The results of this expression lists all that meet the Publication_Date expression but ignors the Expiration_Date expression. I have also tried the below expression and the Expiration_Date expression is the only one that effects the results:
    Expiration_Date >= #Now AND Title LIKE "x"

    Items that have no "x" in the title are still being shown. Am I the only one esperiencing this? I didn't see anything in the Known Issues section.
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    21 Nov 2008
    Link to this post
    Hello Richard,

    You should put #Now in quotes like this:

    1. Publication_Date <= "#Now" AND Expiration_Date >= "#Now"
    2. Expiration_Date >= "#Now" AND Title LIKE "x"

    Do let us know if this helps.

    Best wishes,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    21 Nov 2008
    Link to this post
    Yes,
    The quotes solved the problem. Thanks for the prompt and helpful reply.

    I didn't find any information as to the available conditions and operands so I am putting together a post for our internal forum that explains the available conditions and operands for the FilterExpression. Once I get the post together, I will add it to this forum so others can use it.

    If there is already documentation on this, would someone post a link so it is easier to locate for others?
  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    24 Nov 2008
    Link to this post
    Hi Richard,

    Filter expression functionality is still not documented as it is new for v3.5. Here are some more details on this matter:

    Supported left operands are
    :
    • All meta keys of the corresponding provider
    • ID
    • Tag.ID
    • Tag.Name
    • ParentID
    Supported join types are:
    • AND
    • OR
    Supported conditions are:
    • =
    • <>
    • >
    • <
    • >=
    • <=
    • IN
    • LIKE
    • IS NULL
    • IS NOT NULL
    As a whole, you should use SQL syntax when you construct the value of the filter expression.

    Hope this helps.

    Sincerely yours,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    26 Nov 2008
    Link to this post
    Is there a way for me to do datatime math in the format expression.  Like pulling only articles that are 30 days old or newer.
  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    27 Nov 2008
    Link to this post
    Hi Chris,

    To achieve the required functionality you need to extend NewsView base class. Here is an example how to display news published within the last month:

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Telerik.News.WebControls; 
    using Telerik.Cms.Web; 
    using Telerik.Cms.Engine; 
    using Telerik.Cms.Engine.ContentViewFiltering; 
    using System.Collections; 
     
    namespace Telerik.News.WebControls 
        public class NewsViewExtender : NewsView 
        { 
            protected override IList CreateDataSource() 
            { 
                ContentFilterBuilder filterBuilder = this.GetFilterBuilder(); 
                if (filterBuilder.IsFilterValid) 
                    return this.Manager.GetContent(base.GetContentStartIndex(), base.GetPageSize(), base.SortExpression, 
                                              filterBuilder.ParseTagFilter(), ContentStatus.Published, null
                                              filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter()); 
     
                return base.CreateDataSource(); 
            } 
     
            protected override ContentFilterBuilder GetFilterBuilder() 
            { 
                ContentFilterBuilder filterBuilder = base.GetFilterBuilder(); 
                DateTime date = DateTime.Now.AddMonths(-1); 
                MetaSearchInfo filter = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", date, SearchCondition.GreaterOrEqual); 
     
                filterBuilder.AddFilter(filter); 
     
                return filterBuilder; 
            } 
        } 
     

    Do let us know if this helps.

    Best wishes,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Schneider
    Schneider avatar
    29 posts
    Registered:
    02 Nov 2008
    18 Dec 2008
    Link to this post
    How can an API be considered finished if it is not documented?

    If Sitefinity want to start getting serious customers they are going to need to start taking development more seriously. There seems to be a lack of discipline within the product development.

    Having to refer to forum posts for documentation is a bit of a joke...
  8. Kalina
    Kalina avatar
    176 posts
    Registered:
    27 Oct 2016
    18 Dec 2008
    Link to this post
    Hi Chris,

    We are constantly working to update our documentation.  However, because of our aggressive development schedule, it happens so that documentation updates lag behind development implementations at certain times.  

    To compensate for that we use other, less formal channels for communication such as the blogs or forums.   This is so that we provide users with some reference until the full and detailed description is prepared.  We are very open to user questions and we try to provide timely guidance regarding the existing functionality both through the forums and support.

    We understand your frustration and will work to improve our documentation delivery scheduling.

    Regards,
    Kalina
    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    18 Dec 2008
    Link to this post
    That wasn't Chris, these forums have helped me for the last 6 months, I am overly impressed with the support provided by sitefinity.
  10. Joe
    Joe avatar
    138 posts
    Registered:
    24 Sep 2012
    18 Dec 2008
    Link to this post
    Hi Chris,

    I recently blogged about filter expressions here:

    http://blogs.sitefinity.com/JosephAnderson/Posts/08-12-17/Filter_Expressions.aspx

    We are in process of adding this to the developer manual, so stay tuned!

    All the best,
    Joe
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Armen
    Armen avatar
    11 posts
    Registered:
    07 Feb 2008
    15 Jan 2009
    Link to this post
    Hi Peppi,

    I have add your presented sample to my App_Code with my filtering conditions and in my costome control used it us follows

    <%@ Register Assembly="App_Code" Namespace="test.WebControls" TagPrefix="test" %>

    <test:NewsViewExtender ID="sfn_NewsViewExt" runat="server" />

    the problem is that I am getting the listing correctly but when I click on some news item to show news details I am getting the error:

    Server Error in '/DCPA' Application.

    The resource cannot be found.

    Description:HTTP 404. The resource you are looking for (or one of its dependencies)could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

    Requested URL:/dcpa/education/test_result/07_09_26/LAUNCH_NATIONAL_TOUR_OF_A_CHORUS_LINE_DIRECT_FROM_BROADWAY.aspx


    Version Information: Microsoft .NET Framework Version:2.0.50727.3053;ASP.NET Version:2.0.50727.3053 


    I am a little stuck with this issue. Can you please help me to solve this problem?

    Thanks,
    Armen

  12. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    20 Jan 2009
    Link to this post
    Hi Armen,

    Is everything working if you remove this class and use the standard NewsView control? Is it possible for you to create a FilterExpression, and directly write it in the NewsView's FilterExpression property? Could you please provide some more details about your project and url rewrite rules that you are using?

    Greetings,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Armen
    Armen avatar
    11 posts
    Registered:
    07 Feb 2008
    23 Jan 2009
    Link to this post

    Hi Georgi

    Everything is working when I am setting the default newsview. The extended news view i have built in the following way. In App_Code I have added a class NewsViewExtender.cs like this

    namespace DCPA.WebControls
    {
    public class NewsViewExtender : NewsView
    {
    public override string FilterExpression {
    get
    {
    return base.FilterExpression;
    }
    set
    {
    base.FilterExpression = value;
    }
    }
    protected override void CreateChildControls()
    {
    base.CreateChildControls();
    }

    }
    }

    and after created my custom control as follows

    <%@ Register Assembly="App_Code" Namespace="DCPA.WebControls" TagPrefix="DCPA" %>
    <sf:CssFileLink ID="CssFileLink1" FileName="~/Sitefinity/ControlTemplates/News/newsCommonLayout.css" Media="screen" runat="server" />
    <div style="text-align:center; width:100%;">
    <telerik:RadComboBox ID="ddlFilter" runat="server" EnableEmbeddedSkins="False" Width="164px" AutoPostBack="True">
    <Items>
    <telerik:RadComboBoxItem Value="All" Text="All News" Selected="true" />
    <telerik:RadComboBoxItem Value="Last" Text="Last month" />
    </Items>
    </telerik:RadComboBox>
    </div>
    <DCPA:NewsViewExtender ID="sfn_NewsViewExt" runat="server" ItemsPerPage="3" AllowPaging="true" />

    and included my control in the toolbox. The listing of news are shown as on default newsview with my dropdown list on top that I am planning to use for filtering the news items loaded as datasource.

    The problem that I am facing is that I am not able to see the news details for specific news items as it is bringing the error that I have specified.

    I have checked the Urls to verify if there are rewritten in different way for my control and default one and can tell that they are same. Pasting Urls of both below from my local env.

    http://localhost/dcpa/education/test/08_02_19/RANKIE_VALLI_TO_APPEAR_AT_DCPA_MARCH_1.aspx - this is diplaying details successfully

    http://localhost/dcpa/education/test_result/08_02_19/RANKIE_VALLI_TO_APPEAR_AT_DCPA_MARCH_1.aspx - this is bringing the same error

    The resource cannot be found.
    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /dcpa/education/test_result/08_02_19/RANKIE_VALLI_TO_APPEAR_AT_DCPA_MARCH_1.aspx

    Can you please advice me on how to handle this issue. Probably I am missing some very important thing.

    Thanks,
    Armen

  14. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    29 Jan 2009
    Link to this post
    Hello Armen,

    Thank you for contacting us.

    To work properly with the details links, your user control should implement the interface IUrlRewriterContainer.
    1. You must implement this interface in your control:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web;
    public partial class Sitefinity_UserControls_TestNewsView : System.Web.UI.UserControl, IUrlRewriterContainer
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    #region IUrlRewriterContainer Members
    public IUrlRewriterService GetUrlRewriterService()
    {
    return sfn_NewsViewExt.GetUrlRewriterService();
    }
    #endregion
    }

    2. Then, edit the page and drag & drop the control.
    Note: If you had previously added that user control you must first delete it from the page and then add it again, so the changes apply.

    All the needed files are attached in this post.

    Hope this information will help you.

    Kind regards,
    Parvan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  15. Gregg
    Gregg avatar
    7 posts
    Registered:
    02 Jun 2008
    08 Sep 2009
    Link to this post
    I am having trouble with the like condition as well. If I use Title LIKE "B%" the result will be a title that has B anywhere in the Title, not just the first character.

    I need to display all of the news items that start with B. Is there a way to do this?
  16. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    11 Sep 2009
    Link to this post
    Hi Gregg,

    A complete fix for this will be available with Sitefinity 4.0. The implementation of the filtering will be different there, and much more efficient. Everything that LINQ can provide you for selecting and filtering, will be available in the Sitefinity 4.0 controls.

    For the time being, you could create a custom ContentView based control, and override the CreateDataSource() in which you should apply the filtering:

    example:
        public class CustomDownloadList : DownloadList 
        { 
            
            protected override IList CreateDataSource() 
            { 
                //Filtering by category. 
                //the same approach can be used for any other filtering 
                //content.GetMetaData("Title").ToString().StartsWith()...       
                IList myItems = base.CreateDataSource(); 
                List<IContent> FilteredItems = new List<IContent>(); 
                foreach (IContent content in myItems) 
                { 
                    if (content.GetMetaData("category") != "something"
                    { 
                        FilteredItems.Add(content); 
                    } 
                } 
                return FilteredItems; 
            } 
     

    I hope this helps. 

    Regards,
    Georgi
    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.
  17. Darshani
    Darshani avatar
    18 posts
    Registered:
    13 Oct 2009
    27 Oct 2009
    Link to this post
    Hi Pepi,

    I am just wondering whether we can use wildcard commands to filter any information that contains a particular string in the Tag. For instance if I want to select all events that have got the Tag as ABC, can I enter in the filter expression as Tag.Name Like "%ABC%"

    It gave me an error saying [FilterExpression: Tag.Name Like ]This method is not supported.

    Any alternative ways please?

    Best Regards,
    Darshani
  18. Darshani
    Darshani avatar
    18 posts
    Registered:
    13 Oct 2009
    27 Oct 2009
    Link to this post
    Hi Pepi,

    I am just wondering whether we can use wildcard commands to filter any information that contains a particular string in the Tag. For instance if I want to select all events that have got the Tag as ABC, can I enter in the filter expression as Tag.Name Like "%ABC%"

    It gave me an error saying [FilterExpression: Tag.Name Like ]This method is not supported.

    Any alternative ways please?

    Best Regards,
    Darshani
    www.eyepax.com
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 Oct 2009
    Link to this post
    Hello Darshani,

    Tags does not support LIKE condition. LIKE can be used for Categories. The problem will be fixed with Sitefinity 4.0 where we will use different Open Access instead of Nolics.

    Kind regards,
    Ivan Dimitrov
    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.
  20. Darshani
    Darshani avatar
    18 posts
    Registered:
    13 Oct 2009
    27 Oct 2009
    Link to this post
    Thanks Ivan,

    Well is there any way to globally categorize all the modules by Tags? For instance i got events, news and generic content that are inter-related.  I use a tag for a particular event and if i use the same for news and content items that are related to the selected event, is it possible for me to display all in a page easily than going for defining tags every time in filter expressions?

    Best Regards,
    Darshani
    www.eyepax.com
  21. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    21 Nov 2016
    29 Oct 2009
    Link to this post
    Hello Darshani,

    Each tag is unique and it is part of only one module. There is no way to get all ContentItems based on one tag between different modules. However you can create a user control that will work with all modules' managers and get items by tag name. This in a way will work like your idea on getting content from different modules by tag name.

    Here is a simple how this is done for GenericContent:

    protected void Page_Load(object sender, EventArgs e)
        {
            var contentManager = new ContentManager();
            var tag = contentManager.GetTag("genTag");
            var taggedContent = tag.TaggedContent;             
             
            foreach(TaggedContent item in taggedContent)
            {
                Response.Write((contentManager.GetContent(item.ContentID)).GetMetaData("Name"));
            }
        }

    You can add the logic for the other modules like News, Blogs, Events etc.

    All the best,
    Nikolai
    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.
  22. Curt Rabon
    Curt Rabon avatar
    2 posts
    Registered:
    31 Dec 2008
    07 Dec 2010
    Link to this post
    I would like to use the NewsViewExtender. Other than coping the code into App_Code folder, what else do I need to do?

    Thanks,
    Curt
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Dec 2010
    Link to this post
    Hi Curt,

    1. You have to override the following properties

    public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx";
            }
     
        }
     
        public override string SingleItemTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx";
            }
     
        }
     
     
        public override Type LocalizationAssemblyInfo
        {
            get
            {
                return this.GetType();
            }
            set
            {
                base.LocalizationAssemblyInfo = value;
            }
        }
     
        public override Type AssemblyInfo
        {
            get
            {
                return this.GetType();
            }
            set
            {
                base.AssemblyInfo = value;
            }
        }

    2. The control has to be registered inside <toolboxControls> section of the web.config.

    Greetings,
    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
  24. Gratian
    Gratian avatar
    9 posts
    Registered:
    05 Nov 2010
    08 Dec 2010
    Link to this post
    Hi all,
    Pepi see that in your example you use something like
    filterBuilder.ParseTagFilter()
     
    in
     
    return this.Manager.GetContent(base.GetContentStartIndex(), base.GetPageSize(), base.SortExpression, filterBuilder.ParseTagFilter(), ContentStatus.Published, null, filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter());

    I would like to sort the content of a view by some preselected tags.
    How is the best way to filter the content i retrieve by an array of tags. Could i create a new filter  (ContentFilterStatement) and add it to the ContentFilterBuilder or maybe even add something in ParseTagFilter (or from what i saw ParseTagsFilter for an array).
    In case of ParseTagsFilter i don't really know how to add the tags filter.
    Thanks.
  25. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Dec 2010
    Link to this post
    Hello Gratian,

    You can use only a single tag. There is no support for filtering by multiple tags,because there is no method of ContentManager class that works with array of tags


    You can try using separate filters where you pass your tag name

    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", "tag1",
    ContentFilter.Condition.Equal,
    ContentFilter.JoinType.And));
     
    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", "tag2",
    ContentFilter.Condition.Equal,
    ContentFilter.JoinType.And));


    Greetings,
    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
Register for webinar
25 posts, 0 answered