2.1 View per page dropdown

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 年 前
Hi All,

Long shot I know, has anyone ever successfully implemented a "per page" dropdown to be able to dynamically change the page size of results?

Thanks in advance!

Dave
12 年 前
inspired wrote:
Hi All,

Long shot I know, has anyone ever successfully implemented a "per page" dropdown to be able to dynamically change the page size of results?

Thanks in advance!

Dave

If you mean to let the customer select page size, then you can set it at each category/manufacturer level in adamin>catalog>category/manufacturer>edit (category/manufacturer)>SEO tab and:

Select: Allow customers to select page size:
Define your sizes dropdown in Page Size options (comma separated): (the first size will be default).


Check example: http://admin-demo.nopcommerce.com/Admin/Category/Edit/50
12 年 前
Hi Eduardo,

I can't see thatsetting in 2.10, do you know if it's available in that version, if not, can it be ripped out and implemented from a newer version?

Many thanks,

Dave
12 年 前
inspired wrote:
Hi Eduardo,

I can't see thatsetting in 2.10, do you know if it's available in that version, if not, can it be ripped out and implemented from a newer version?

Many thanks,

Dave


Hi Dave:

That feature came out in v2.3. Maybe it is easier to upgrade. You can check the change set in:
http://nopcommerce.codeplex.com/SourceControl/changeset/changes/8be4fc135408
12 年 前
Yeh I thought it may have, unfortunately my client needs the sagepay extension which is only supported up to 2.1 so I'm stuck with that version :(
12 年 前
inspired wrote:
Yeh I thought it may have, unfortunately my client needs the sagepay extension which is only supported up to 2.1 so I'm stuck with that version :(

My guess is that as a plugin it will not be difficult to install that extension in v2.3. Have you checked it with Carlos Martínez? (developer of that extension).
12 年 前
No I haven't spoken to him about upgrading or implemeting it, namely because our site is almost ready to go live and I have a lot of custom code in it.

Do you know ehre 2.1 gets the pagesize from the database in order to render the correct amount of products per page?

I'm thinking I might be able to do something with sessions and pull it into that function, and control the pagesize session via a dropdown on the results.

Many thanks,

Dave
12 年 前
I've managed to get this working, here's what I did:

Category.cshtml (top of page)

if(Session["pageSize"] == null)
    {
        Session["pageSize"] = 12;  
    }


Then where you want the dropdown to appear:

<select name="perPage" id="perPage">
                        <option value="12"@if(Session["pageSize"].ToString() == "12"){<text>selected="selected"</text>}>12</option>
                        <option value="24"@if(Session["pageSize"].ToString() == "24"){<text>selected="selected"</text>}>24</option>
                        <option value="48"@if(Session["pageSize"].ToString() == "48"){<text>selected="selected"</text>}>48</option>
                        <option value="96"@if(Session["pageSize"].ToString() == "96"){<text>selected="selected"</text>}>96</option>
                    </select>


CategoryService.cs

public virtual IPagedList<Category> GetAllCategories(int pageIndex, int pageSize, bool showHidden = false)
        {
            var categories = GetAllCategories(showHidden);
            return new PagedList<Category>(categories, pageIndex, Convert.ToInt32(System.Web.HttpContext.Current.Session["pageSize"]));
        }


The just use a bit of jQuery to detect when the dropdown is changed, I add view=xx to the querystring and then have the following in ProductService.cs

Replace:
var products = new PagedList<Product>(query, pageIndex, pageSize);


With:

if (System.Web.HttpContext.Current.Session["pageSize"] == null)
            {
                System.Web.HttpContext.Current.Session["pageSize"] = 12;
            }

            if (System.Web.HttpContext.Current.Request.QueryString["view"] != null)
            {
                System.Web.HttpContext.Current.Session["pageSize"] = Convert.ToInt32(System.Web.HttpContext.Current.Request.QueryString["view"]);
            }

            var products = new PagedList<Product>(query, pageIndex, Convert.ToInt32(System.Web.HttpContext.Current.Session["pageSize"]));


And there you go, thanks for the Inspiration Eduardo!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.