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

Forums / Developing with Sitefinity / What method to override in order to filter generic content?

What method to override in order to filter generic content?

7 posts, 0 answered
  1. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    09 Jan 2009
    Link to this post
    Hopefully this will be a quick answer.  I can't see what method to override in  ProductsView.cs in order to be able to filter the content.  I'd like to filter the listing of content based on the values in the meta fields

    I know how to do the filtering itself, using IMetaSearchInfo and setting up filter arrays...I just don't know how to plug that into ProductsView.cs.  There must be some base method that gets the data and binds it to the repeater, right?  Is it OnDataBinding?

    Thanks,
    Mike
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    09 Jan 2009
    Link to this post
    Hi Mike,

    Please refer to the following KB which provides an example how to implement a custom filter for NewsView control (it is ContentView based control): How to display news published within the last month. Analogically, you should achieve the required functionality in ProductsView control.

    Do let us know if you need any further assistance.

    Best wishes,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    09 Jan 2009
    Link to this post
    Excellent; that was exactly what I was looking for.  Thanks for the quick response, Pepi, it saved the day!

    Regards,
    Mike Sharp
  4. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    09 Jan 2009
    Link to this post
    Hi Pepi,

    That worked well to filter the content, but unfortunately the pager is still looking at the original data source.  I'm using the pager from the products module, basically unchanged.  How do I bind the pager to the same datasource?

    <

     

    sfWeb:Pager ID="pager2" runat="server">
       [...] templates here [...]

     

  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    10 Jan 2009
    Link to this post
    Hello Mike,

    You need to override SelectContentCount method as well. Here is an example:

    protected override int SelectContentCount() 
            { 
                ContentFilterBuilder filterBuilder = this.GetFilterBuilder(); 
               
                int contentCount = contentCount = Manager.GetContent(0, 0, SortExpression, 
                                              filterBuilder.ParseTagFilter(), ContentStatus.Published, null
                                              filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter()).Count; 
     
                if (LimitListCount && contentCount > MaximumListCount) 
                    contentCount = MaximumListCount; 
     
                return contentCount; 
            } 

    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.
  6. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    10 Jan 2009
    Link to this post
    thanks Pepi, that did it.  I found in my case I had to wrap the whole thing in a conditional, and call the base class if my filter wasn't in the query string.  Like:

    protected override int SelectContentCount()
    {
     if (!string.IsNullOrEmpty(Context.Request.QueryString.Get("boxfilter")))
     {
      ContentFilterBuilder filterBuilder = this.GetFilterBuilder();
      int contentCount = contentCount = Manager.GetContent(0, 0, SortExpression,
          filterBuilder.ParseTagFilter(), ContentStatus.Published, null,
          filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter()).Count;
      if (LimitListCount && contentCount > MaximumListCount)
       contentCount = MaximumListCount;
      return contentCount;
     }
     return base.SelectContentCount();




    Say, what happened to the button on the editor in this forum that lets you paste code? 

    Regards,
    Mike Sharp
  7. Kalina
    Kalina avatar
    176 posts
    Registered:
    27 Oct 2016
    12 Jan 2009
    Link to this post

    Hello Mike,

    Regarding the missing button which allows users to paste code in the body of the messages: a fix to this problem was provided and will be uploaded to the live site within the following days.

    We apologize for the inconvenience.

    Regards
    Kalina
    the Telerik team


    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
7 posts, 0 answered