OrderBy in Widget using PageSelectorItem

Eric Erskine asked on June 3, 2024 17:31

I have built a widget (based on a view component) that has a PageSelectorItem as a property. I am using this to select content from a specific folder.

[EditingComponentProperty(nameof(PageSelectorProperties.RootPath), "/Reused-Content/Service-Blocks")]

In my view component, I am retrieving the content blocks that the user selected using

var serviceBlockGuids = _componentPropertiesRetriever.Retrieve<ServiceBlocksProperties>().ServiceBlocks
            .Select(i => i.NodeGuid)
            .ToList();

However it is returning the blocks in Node order, not in the order that they are selected. When I edit the widget, they are shown in the order they were selected. Is there any way to retrieve them (or sort them) in the order they are selected?

Recent Answers


Juraj Ondrus answered on June 4, 2024 13:09

I am afraid but the order value is not stored anywhere. The page selector just saves the NodeGUID values into the JSON in given order (CMS_Document -> DocumentPageBuilderWidgets). This means that if you want to get the order, you need to get the JSON value for your widget property and then load the pages based on the NodeGUID in given order as they are stored in the JSON.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 4, 2024 14:59

Eric,

This is a huge downfall of the selector. We've attempted many times to order by how they are selected in the selector, but it doesn't seem that logic is applied when saving the json in the field on the page. Unfortunately, I have no good solution aside from making your own custom control based on the PageSelectorItem and customizing how you can order them.

0 votesVote for this answer Mark as a Correct answer

Eric Erskine answered on June 4, 2024 21:32

Well that stinks. Kentico is obviously using the JSON values when populating the selector pop-up. And I see the correct order in the JSON in the CMS_Document table. Just don't want to spend the time creating a whole new control when the one provided should do this out of the box.

Thanks for your insights.

Eric

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 4, 2024 21:33

But is that order based on how you select the pages or some random order? We've not found any consistency to it at all.

0 votesVote for this answer Mark as a Correct answer

Eric Erskine answered on June 6, 2024 00:09

I seems pretty consistent that it is the order that I added them to the list. I have to select them one at a time and save it each time, but then it stays in that order in the 'edit' modal. I can even see the order that I selected them in the JSON values in the database table. If I reorder the content in the content tree, it stays in the original order in the JSON until I republish the page.

I was hoping to create an A/B test with different widget values. Will have to think of a different way to do it.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.