Developer forum

Forum » Development » items api sort by user-defined

items api sort by user-defined

Remi Muller
Reply

I am loading items through the Dynamicweb.Content.Items api. Working fine and I can sort on different fields.
My issue is I can not figure out how to sort on “user defined” order as set in the dw backend.

 

Here is a code sample trying to sort on user-defined which does not work :(

 

ItemManager.Initialize();
using (Repository repository = ItemManager.Storage.Open("Brochure_Detail"))
{
    Query query = new Query();
    query.Fields = new List() { "Titel" };

    query.OrderBy = new OrderByCollection();
    query.OrderBy.Add(new OrderBy("UserDefined", OrderByDirection.Ascending));
    query.Offset = 0;
    query.Amount = 1000;

 

    var AllItems = repository.SelectByParentPageId(2339, query, false, false, false);
    foreach (var item in AllItems)
    {
        //do stuff with item in user defined order :)
    }

}

 

 

Who can tell how to achieve this?

 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Remi

 

I've asked a developer to look into this.

 

BR Nicolai

 
Remi Muller
Reply

Has he looked at it yet? I kind of need this now :(

 
Mikkel Ricky
Reply

Try sorting on "Sort", i.e.

query.OrderBy.Add(new OrderBy("Sort", OrderByDirection.Ascending));

Best regards,
Mikkel

 

 

 
Remi Muller
Reply

Tested on 8.2.3.10 and to be sure with 8.3.0.5.

On 8.3.0.5 i do not get an error anymore that the field "Sort" does not exist. But it is not sorted correctly as it is in the backend.

 

 

 

 
Merethe Nielsen
Reply

I have created an investigation item for this: 13329.

 
Mikkel Ricky
Reply

I've tested on 8.3.0.5 and it works (for me) using a Razor paragraph template like this to load item pages below the current page:

@using System.Collections.Generic;
@using Dynamicweb.Content.Items;
@using Dynamicweb.Content.Items.Queries;

@{
	IEnumerable<Item> allItems = null;
	ItemManager.Initialize();
	using (var repository = ItemManager.Storage.Open("Brochure_Detail")) {
		var query = new Query();
		query.Fields = new List<string>() { "Sort", "Name" };
		query.OrderBy = new OrderByCollection();
		query.OrderBy.Add(new OrderBy("Sort", OrderByDirection.Ascending));
		query.Offset = 0;
		query.Amount = 1000;

		allItems = repository.SelectByParentPageId(Pageview.Page.ID, query, false, false, false);
	}
}

@if (allItems != null) {
	<ol>
	@foreach (var item in allItems) {
		<li>@item["Name"] (sort: @item["Sort"])</li>
	}
	</ol>
}

Do you have a solution I can take a look at?

 

 
Remi Muller
Reply

On a clean dw 8.3.0.5 solution it does work indeed.

The current solution is not available public yet. Let me verify the upgrade or rerun to be sure. I will get back to you.

I am als not sure if i should go live with 8.3 build yet.

From which dw version has the sort column been introduced? If it is available from 8.2 then i rather run 8.2 latest build in production.

Do you think 8.3.0.5 is production ready?

 

 

 

 
 
Merethe Nielsen
Reply

Hi

The Sort column was introduced with 8.3 and is not available in 8.2.

Yes, 8.3.0.5 is production ready. There are approx 160 live solutions that runs 8.3+.

Kind regards,
Merethe Nielsen

 

 

 

 

 

 

You must be logged in to post in the forum