Try our conversational search powered by Generative AI!

Episerver sorting order of pages should not effect website pages sorting order

Vote:
 

When editor changes sorting order of the pages in Episerver editing mode, its affecting the website pages sort order also. means website pages are also changes sorting order that happens in episerver.

how we can sort order of pages in episerver in a way that it should not affects website page sorting order.

Is there any configuration or settings in episerver?

#198311
Edited, Oct 25, 2018 8:17
Vote:
 

Hi Janmejay,

I'm intrigued—what scenario do you have where you would want the sort order to differ between edit mode and what visitors see? Reordering content is (usually) done expressly to change the order content appears on the site and not just for editor convenience (similarly, don't editors expect content to be structured as visitors see it?).

With that disclaimer, if you wanted to build a menu with a different sort order (for example) couldn't you just introduce a new sort index property and use LINQ to order by that?

Something like:

public virtual int MenuSortIndex { get; set; }

and then:

pages.OrderBy(x => x.MenuSortIndex);
#198330
Edited, Oct 25, 2018 16:09
Vote:
 

Hi Jacob,

We have already sorting implemented in application. and its working well. but now editor wants that, website should show always latest fisrt articles even if editors changes the sort order of pages in episerver.

for that one option i am thinking is to go every places where we are getting the pages for all the blocks and apply OrderByDescending(x =>x.StartPublish) so it will return latest first.

we are using now 

 List<PageData> children =

DataFactory.Instance.GetChildren(pageLink, LanguageSelector.AutoDetect(true)).Where(c =>c.CheckPublishedStatus(PagePublishedStatus.Published)).ToList();

in this query if i apply OrderByDescending(x =>x.StartPublish)  then its returning the latest first. but the problem is we have many blocks with different page type and i have to go every places and apply OrderByDescending(x =>x.StartPublish) to make sure that application should return latest first always.

So i wanted to know that is there any configuration or any easy way to do this?


#198373
Oct 26, 2018 7:37
Vote:
 

avoid `DataFactory` type if you are on some latest Episerver versions..

don't think that there is some global switch to perform this sorting unobtrusively for you. and IMHO it might be even harmful in some places where you would not like to receive pages back in some sorted order. so I think that this explicit sorting is best bet.

#198374
Oct 26, 2018 8:01
Vote:
 

What Can i use instead of DataFactory?

We are using Episerver 10

#198376
Edited, Oct 26, 2018 8:12
Vote:
 

`IContentRepository` that you got from IoC container via constructor injection (preferrably)

#198377
Oct 26, 2018 8:14
Vote:
 

I am trying to make this query to use IContentRepository but i am getting error

Current query:-

DataFactory.Instance.GetChildren(pageLink, LanguageSelector.AutoDetect(true)).Where(c =>c.CheckPublishedStatus(PagePublishedStatus.Published)).ToList();


I tried:- 

var loader = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentLoader>();

loader.GetChildren(pageLink, LanguageSelector.AutoDetect(true)).Where(c => c.CheckPublishedStatus(PagePublishedStatus.Published)).OrderByDescending(x => x.StartPublish).ToList();


I am gettin compilation error

 


                        
#198387
Edited, Oct 26, 2018 8:41
Vote:
 

GetChildren from the injected services are generic so should be called with the type. Try

GetChildren<PageData> instead or you can pass whatever base types you use.

Also make sure to use IContentLoader when you are just reading and IContentRepository when you need to update/save things, it's better performance.

#198400
Oct 26, 2018 11:41
Vote:
 

Also as a guide you never want to call EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance in code, you want to pass your services in the constructor of your classes or lazy load them using Injected<T> (preferrable contructor injected as Injected<T> is a bit of an anti pattern)

#198402
Oct 26, 2018 11:45
Vote:
 

Also as a guide you never want to call EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance in code, you want to pass your services in the constructor of your classes or lazy load them using Injected<T> (preferrable contructor injected as Injected<T> is a bit of an anti pattern)

#198403
Oct 26, 2018 11:45
Vote:
 

Its working thanks

#198406
Oct 26, 2018 12:09
Vote:
 

Janmejay,
As a courtesy, please click the Mark Answer button on the reply that solved your problem. Thanks.

#198417
Oct 26, 2018 18:35
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.