Developer forum

Forum » Templates » Sorting products in razor

Sorting products in razor

Filip Lundby
Reply

How can I sort products the same way they are sorted in backend?

Something like ...

@foreach (LoopItem i in GetLoop("Products").OrderBy(p => p.Sort)) {

// ...

}


Replies

 
Nicolai Høeg Pedersen
Reply

That would just work for that part of the list you are looking at now. I.e. 10 products on page 1. That is not good if you have 10 pages of 10 products.

You can set the sort order on the paragraph settings - see "Sort by" in the manual: http://manual.dynamicweb-cms.com/Default.aspx?ID=4392

You can also sort using querystring: ?SortBy=UserDefined&SortOrder=desc

 
Filip Lundby
Reply

Thanks Nicolai.

And how about the groups - how are they sorted? If I in the paragraph settings under Settings choose to use "Product groups" instead of "Products" - it doesn't seem like they are sorted the same way as the products. 

 
Nicolai Høeg Pedersen
Reply

They should be sorted by the sort in the admin

 
Filip Lundby
Reply

I am outputting the groups on two pages, but the sorting is different on each page. However the settings are the same: http://screencast.com/t/0nYnQKqpMROV - Changing the settings doesn't have any impact in frontend. I'm using the same loop on both pages: @foreach (LoopItem i in GetLoop("Groups"))  {  }

 
Nicolai Høeg Pedersen
Reply

Hi Filip

Hard to tell - we need a URL to both pages to take a look. Please post, or contact service desk to help you out.

BR Nicolai

 

You must be logged in to post in the forum