Developer forum

Forum » Development » Paging

Reply

Hello.

Currently I’m working on a big ecommerce site integrated with Navision. It’s important to us, and the customer, that we have good performance on the site. On the FrontPage we have a box with 4 tabs each of these tabs renders a different product group list. We don’t want to have page refresh when a user clicks on one of the tabs and we don’t want to loads all 4 product groups and just hide the divs. The reason for this is that every product in the list does a live price calculation @ Navision and this is a bit “expensive”. Therefor the solution I have made is a custom module where u can define a GroupID, tab name and the productListTemplate. I also have a “active” checkbox so I know which one to render on page load. When a user clicks a tab I do a ajax request to the server with the GroupID. This all works quit fine. But now I’m stuck at the paging part. This is the method I use when rendering list.

Group g = new Group(groupID);

            ProductCollection pg = Product.getProductsFromGroup(g);

            Renderer r = new Renderer(Pageview, ParagraphRow);

           

            r.ParagraphSettings.PageSize = 8;

            r.ParagraphSettings.TotalProductCount = pg.Count;

            r.ParagraphSettings.PageSizeBack = 1; //test

           

            r.RenderProducts(pg, productListTemplate);

 

            htc.Response.Write(productListTemplate.Output());

            htc.Response.End();

 

By reflection the DW code I found out that PageSize is the one set in the standard eCommerce Catalog for how many products we want per page and TotaltProduct Count, well yes is the total product count. Total works fine, but I can’t seem to get the PageSize to work? No matter what I do, it just renders all products. And for some reason it always writes xx products found Page 2 of 4. This 2 of 4 – and I can’t seem to figure out what I’m missing.

It would also be cool if I could make this paging work with ajax.

 

Any ideas?

Thanks! 


Replies

 
Reply

Hi Mikkel,

If I look at the implementation of RenderProducts, it seems to simply loop over the entire collection of products you pass to it, ignoring the paging settings. I think the paging settings are simply used to render the interface (e.g. forward and back links and so on), while you need to do the actual paging yourself. Here's a quick example that seems to work for me:

public class Frontend : ContentModule
{
  public override string GetContent()
  {
    int pageSize = 4;
    Dynamicweb.Templatev2.Template template = new Dynamicweb.Templatev2.Template("TestModule/test.html");
    ProductCollection pg = Product.getProductBySQL("SELECT * FROM EcomProducts");
    Renderer r = new Renderer(Pageview, ParagraphRow);

    r.ParagraphSettings.PageSize = pageSize;
    r.ParagraphSettings.TotalProductCount = pg.Count;

    int startPage = !string.IsNullOrEmpty(Base.Request("PageNum")) ? Convert.ToInt32(Base.Request("PageNum")) - 1 : 0;
    int startIndex = r.ParagraphSettings.PageSize * startPage;
    int maxRecord = Math.Min(startIndex + pageSize, pg.Count);

    // Copy over the current page of records
    ProductCollection result = new ProductCollection();
    for (int i = startIndex; i < maxRecord; i++)
    {
      result.Add(pg[i]);
    }
    r.RenderProducts(result, template);
    return template.Output();
  }
}

This code comes from a simple Custom Module which as a Request property and returns the HTML of the template, but the idea is the same.

I also looked at the Edit page of the Product Catalog module and it seems that PageSizeBack and other PageSize* properties are all commented out so it looks like they are no longer used.

Hope this helps. If not, please let me know.

Cheers,

Imar

 
Reply
 HI Imar!

I totally forgot to answer and say thank u very much! It was much more simple than i made it to be - i was so hooked on using the API that i forgot to think for my self :) - So your solution worked and i got my module to work with ajax paging and everything :)

 

You must be logged in to post in the forum