Advanced Pager

Topics: Developer Forum
Mar 1, 2009 at 5:31 PM
Hello,

Does anyone managed to implement the Advanced Pager Add-on ?
Because on the n2cms site the info seems truncated.

Thanks,
Mar 1, 2009 at 7:33 PM
What's your problems?
Mar 1, 2009 at 8:18 PM
I didn't find any info on how to use it.
Mar 2, 2009 at 7:04 AM
It's a simple UserControl.
That's a list of actions to turn it on:
1) Register this control on *.aspx page
2) Set main control attributes/methods (you can do it on page or in code behind levels) like Total, PerPage
3) And refresh the page...

ASPX Page
<%@ Register TagPrefix="parts" TagName="advPager" Src="~/Addons/AdvancedPager/UI/PagerControl.ascx" %>

<parts:advPager runat="server" ID="YourID" Total="<%$ CurrentPage:TotalNews %>" PerPage="<%$ CurrentPage:PerPageNumber %>" PageKeyLiteral="p" MaxPagesBeforeTrimming="7" PageOffset="2" PagerStyle="range" CssClass="float-left" TotalClass="float-right total" TotalPreText="Total:"/>

This control requires two mandatory attributes: Total and PerPage, you could provide variables for them on any levels.
Mar 2, 2009 at 7:35 AM
Thanks, got it.

But this works only for NewsList ?
Anyway, i managed to create a new Template with seo pagination of the children list.
Mar 2, 2009 at 9:31 AM
It will works anywhere...
Mar 9, 2009 at 12:09 PM
I have downloaded the Advanced Pager 1.0 add-on from the N2 website. When I unzip the file, I get a folder structure like below:

AdvancedPagerUserControl
       |
      +--- Addons
       |           |
       |          +--- AdvancedPager
       |                          |
       |                         +--- UI
       |                                   |
       |                                  +--- PagerControl
      +--- Bin
               |
              +--- AdvancedPager.dll

I am using the N2.Everything-vs2008 project from the source code. When I look in the Add-ons folder in the Solution Explorer in Visual Studio, I can see that their are projects used for the Wiki add-on etc.
Can somebody explain why their is no such project file in the downloaded add-on (Advanced Pager 1.0)? How can I install this Advanced Pager 1.0 add-on?


Thanks in advance
Jochen
Mar 9, 2009 at 1:21 PM
This control you can use only by including into *.aspx files.

Mar 13, 2009 at 10:37 AM
I followed the above instructions, but it does not work! The pager appears on the page, but won't work. How knows the pager which datasource must be used?? This is my NewsList.aspx page:

<%@ Register TagPrefix="parts" TagName="advPager" Src="~/Addons/AdvancedPager/UI/PagerControl.ascx" %>
<%@ Page Language="C#" MasterPageFile="~/Templates/UI/Layouts/Top+SubMenu.master" AutoEventWireup="true" CodeBehind="NewsList.aspx.cs" Inherits="N2.Templates.UI.Views.NewsContainer" Title="" %>
<asp:Content ContentPlaceHolderID="PostContent" runat="server">
    <n2:ItemDataSource id="idsNews" runat="server" />
    <asp:Repeater runat="server" DataSourceID="idsNews">
        <HeaderTemplate><div class="list"></HeaderTemplate>
        <ItemTemplate>
            <div class="item i<%# Container.ItemIndex %> a<%# Container.ItemIndex % 2 %>">
                <span class="date"><%# Eval("Published") %></span>
                <a href='<%# Eval("Url") %>'><%# Eval("Title") %></a>
                <p><%# Eval("Introduction") %></p>
            </div>
        </ItemTemplate>
        <FooterTemplate></div></FooterTemplate>
    </asp:Repeater>
    <parts:advPager runat="server" ID="testID" Total="10" PerPage="2" PageKeyLiteral="p" MaxPagesBeforeTrimming="7" PageOffset="2" PagerStyle="range" CssClass="float-left" TotalClass="float-right total" TotalPreText="Total:"/>
</asp:Content>

What am I doing wrong?

Mar 15, 2009 at 8:45 AM
Pager doesnt use the datasource like other ASP.NET controls, instead of this pager need Total attribute, which is an integer number of total pages in some container.
Starting from text above, your version is right at first look and it should works. I will check this out.
Mar 15, 2009 at 9:18 AM
I've just made a new version 1.1 some issues are fixed.
You can download this release from here.
I can't update my record in Addons directory at n2cms.com.
Coordinator
Mar 15, 2009 at 9:51 PM
I've done some fixes to the add-on add-on. Could you try updating again please?
Mar 15, 2009 at 10:16 PM
Add-on system doesnt recognize me as author of this addon.
Coordinator
Mar 15, 2009 at 10:26 PM
I might have used the incorrect username. I changed it to "SerZHio". Could you try once again?
Mar 16, 2009 at 11:33 AM
Edited Mar 16, 2009 at 11:54 AM
I've downloaded your new pager, but the above code in NewsList.aspx still won't work. Like you can see, I have hard coded the Total and PerPage attributes. Is this wrong?

In the N2 back-end, my pages look like this:

Hosted by imgur.com

I have replaced the Total-attribute with 6 and the PerPage attribute with 2. Are these numbers wrong? This is only for testing purposes because I don't know where to find or declare the <%$ CurrentPage:TotalNews %> or <%$ CurrentPage:PerPageNumber %> values. Can someone help me?

My webpage looks like this:

Hosted by imgur.com
Like you can see, the pager appears on the webpage, but all my newsitems appear on the same page! What can possibly be wrong?
Mar 16, 2009 at 2:14 PM
Heh... this pager work is only to show how many pages of news in container not more.
If you want your page to output news by pages you should write such mechanism by yourself.
For paging you should catch 'p' parameter from querystring and make some work.
If you want to create TotalNews method, refer to this code (this code should be implemented in NewsContainer ContentItem):
        public virtual int TotalNews
        {
            get {
                var filters = new ItemFilter[] {new PublishedFilter(), new AccessFilter(), new TypeFilter(typeof(NewsItem))};
                return GetChildren(filters).Count();
            }
        }

For paging capability add some functions to NewsContainer template:
1) add a repeater to *.aspx page
2) in code-behind at OnInit phase add next code:
NewsRepeater.DataSource
                    = N2.Find.Items
                        .Where
                        .Parent.Eq(CurrentItem).And
                        .Type.Eq(typeof(NewsItem))
                        .Filters(filters)
                        .FirstResult(pNum * CurrentItem.PerPageNumber)
                        .MaxResults(CurrentItem.PerPageNumber)
                        .OrderBy.Published.Desc
                        .Select<NewsItem>();
NewsRepeater.DataBind();
P.S.:  pNum is current page number from querystring...


Oct 25, 2010 at 10:07 AM

Hi,

This is a fairly old post, however, I have just started using N2 cms and I am now looking at integrating the AdvancedPager add-on. I have registered my the control to the page and it works as expected if I hard-code the values into the element e.g.

 

 

 

<AddOn:Pager runat="server" ID="pager1" PageKeyLiteral="p" PerPage="5" MaxPagesBeforeTrimming="6" Total="30" PagerStyle="range" TotalPreText="Total no. of items: " CssClass="Pager" />

Obviously this isn't ideal as I need my pager to be dynamic as the count of items can very and the items per page are going to be customizable. So what I have been doing is setting these fields based on the Model like so:

<AddOn:Pager runat="server" ID="pager1" PageKeyLiteral="p" PerPage="<%= Model.ItemsPerPage %>" MaxPagesBeforeTrimming="6" Total="<%= Model.ItemCount %>" PagerStyle="range" TotalPreText="Total no. of items: " CssClass="Pager" />

However, this always results in the following error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace: 

Server Error in '/' Application.

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error: 

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7471287
   System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) +115
   System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info) +192
   System.Double.Parse(String s) +23
   N2.Addons.AdvancedPager.UI.PagerControl.Page_Init(Object sender, EventArgs e) +149
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnInit(EventArgs e) +99
   System.Web.UI.UserControl.OnInit(EventArgs e) +77
   System.Web.UI.Control.InitRecursive(Control namingContainer) +333
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378


Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4927

 

If I check those particular properties (whilst the values are hard-coded) they always have a value so I can't understand when I use them directly that this error gets thrown up It is like the properties haven't been set before the page is rendered. Is this possibly an issue with the control?

Oct 27, 2010 at 10:13 PM

I would recommend going with this pager http://www.west-wind.com/weblog/posts/114621.aspx

I use it on all of my projects and it required just a little bit of modifications to make it work with N2, since both this pager and N2 with default settings are using "page" querystring.

Other than that, this is superior solution. Please inspect it and I can email you source code with examples. Basically, it all comes down to this code on News Listing page

            NewsListing.DataSource = NewsPager.FilterIQueryable(CurrentPage.GetItems().AsQueryable());
            NewsListing.DataBind();

with model

    public class NewsContainer : ContentPage
    {
        public IQueryable<NewsPage> GetItems()
        {
            return N2.Find.Items.Where.Type.Eq(typeof(NewsPage))
                .Filters(new ParentFilter(this), new NavigationFilter())
                .OrderBy.Published.Desc
                .Select().AsQueryable().OfType<NewsPage>();
        }
    }

 

Oct 28, 2010 at 8:38 AM

I ended up creating my own custom pager control.

I would be happy to see some of your examples though?