Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

custom sort order for SiteTree in CMS


Go to End


6 Posts   4336 Views

Avatar
Anatol

126 Posts

10 February 2010 at 2:32pm

Hi,

I'm looking for a way to apply a different sort order of the pages in the site tree in the CMS (the site tree on the left under the create, search and batch action buttons). By default this is ordered by the "Sort" column which makes perfect sense. For my project it would be better though to sort pages by a (new custom) field "Date" (in the `Page` database table).

I have been looking through the source code for quite a while now but couldn't find the right piece of code. Does anyone know where I could find this or how to change it?

Cheers!
Anatol

Avatar
MateuszU

Community Member, 89 Posts

10 February 2010 at 2:49pm

What about SiteTree::$default_sort ? :)

Avatar
Anatol

126 Posts

10 February 2010 at 3:51pm

Hi Mateuzs,

thank you for that! This works well (e.g. in /mysite/_config.php)

SiteTree::$default_sort = 'LastEdited';

The only problem left is that it only works for database fields of the SiteTree table. I extended the Page type with

public static $db = array(
		'Date' => 'SSDatetime'
);

I would like to sort by 'Date' (which is in the database table 'Page', and I guess that's the problem).

Any hint is much appreciated.

Cheers!
Anatol

Avatar
dacar

Community Member, 173 Posts

3 March 2010 at 2:40am

Hi, same problem here. It is no problem to change the order in the frontend templates. But how to change it in the cms sitetree if you want to order by a field written into an other table (eg. page)?

Can anybody help?

Avatar
MarcusDalgren

Community Member, 288 Posts

15 February 2011 at 1:06am

A late reply perhaps but yes!

There is a tutorial about it here.

Avatar
Lisa Diane

Community Member, 1 Post

20 February 2011 at 10:36pm

Edited: 20/02/2011 10:36pm

Thanks you for sharing

__________________
Watch Unknown Online Free