List or Grid View - Make list the default

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi everybody

nopCommerce can display store items in list or grid (View as: List/Grid)

Is there a way to set the ListView as default? Preferable from within admin?

Markus

PS: I could make change to the code but don't like this because on updates sometimes you have to remember to fix everything you customized. So I try to keep it pure :_)
12 years ago
Unfortunately, this option was remove in 2.X version.

You will have to do it manually like this:

1. Go to admin area > configuration > settings > all settings
2. Find 'CatalogSettings.AllowProductViewModeChanging' setting ans set its value to 'false'
3. Open \src\Presentation\Nop.Web\Controllers\CatalogController.cs file
4. Find Category(int categoryId, CatalogPagingFilteringModel command) method
5. Replace

model.PagingFilteringContext.ViewMode = command.ViewMode;


the following code

model.PagingFilteringContext.ViewMode = "list";
12 years ago
If you change the code the above way you will have to do it in more than one place. Additionally, if you change your mind and want the user to have the option to choose between list and grid it won't work anymore. Another alternative is to ensure when the model CatalogPagingFilteringModel is created that the default view mode is "list".

Therefore, change the following lines of code in CatalogPagingFilteringModel.cs

        public CatalogPagingFilteringModel()
        {
            this.PriceRangeFilter = new PriceRangeFilterModel();
            this.SpecificationFilter = new SpecificationFilterModel();
        }


to

        public CatalogPagingFilteringModel()
        {
            this.PriceRangeFilter = new PriceRangeFilterModel();
            this.SpecificationFilter = new SpecificationFilterModel();
            this.ViewMode = "list"; // make default view
        }
12 years ago
Thanks for the feedback.

Don't want to change code because I would have to remember on every update where I changed what. Usually try to keep stuff at it's core.

Sine this seemed to have ben possible I hope the feature makes it back to 2.3 or 2.4

Markus
12 years ago
I second that. Hope to see it implemented again :-)
12 years ago
Is there a work item for this to be added back into nop?
12 years ago
http://nopcommerce.codeplex.com/workitem/10358
12 years ago
For those using NON SOURCE 2.3,

I edited the 'CategoryTemplate.ProductsInGridOrLines.cshtml' file. Changing the line

if (Model.PagingFilteringContext.ViewMode == "list")

from list to grid and swap the grid and list sections around to look like this:

    @*product list*@
    @if (Model.Products.Count > 0)
    {
        if (Model.PagingFilteringContext.ViewMode == "grid")
        
        {
            @*grid mode*@
            <div class="product-grid">
                @(Html.DataList<ProductModel>(Model.Products, 2,
                    @<div class="item-box">
                        @Html.Partial("_ProductBox", @item)
                    </div>
                ))
            </div>
        }
    else
    {
            @*list mode*@
            <div class="product-list">
            @foreach (var product in Model.Products)
            {
                <div class="item-box">
                    @Html.Partial("_ProductBox", product)
                </div>
            }
            </div>

I was then able to (in Admin "Catalog Settings") disable "Allow view mode changing" and retain the list view as permanent (with option to re-enable if required).

I did this, because changing the view setting to list & disable changing was not permanent = every time I returned to Home page & reselect a product, it reverted to grid view [non src nop2.3]

Hope this helps, Cheers
12 years ago
Is this fixed in 2.40 ? How to set default?
12 years ago
ezhil wrote:
Is this fixed in 2.40 ? How to set default?

Just update 'catalogsettings.defaultviewmode' setting ("grid" or "list").
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.