Rahul - Systematix
Rahul - Systematix

Reputation: 77

Kentico 9 - Apply sorting on content tree based on custom field

In Kentico 9, need guidance to achieve following scenario:

I have a custom page type like "Appointments" in which I have a custom fields with name "AppointmentDate". I have created a folder into content tree with name "All appointments" , under that created some folder for years like 2016,2015, etc.

Now when I add an "Appointment" type under a year folder like "2016", I need ti should be insert Order by "AppointmentDate" in tree. Like follows

- All Appointments
---- 2016
-------- Ap1  (AppointmentDate fields = 5 May 2016)
-------- Ap2   (AppointmentDate fields = 6 Jun 2016)
--------- Ap3   (AppointmentDate fields = 25 Jun 2016)

So if now add new appointment with name like "App4" where set "AppointmentDate fields = 11 Jun 2016", so it should be insert between Ap2 and Ap3 under content tree in Admin panel.

Hope I am clear with my query.

Thanks in advance.

Upvotes: 2

Views: 297

Answers (1)

Martin Makarsky
Martin Makarsky

Reputation: 2650

You can attach to global event

DocumentEvents.Create.After += Document_Create_After;

and in document create after method check for the path of your page and desired page type. If it`s node you need to order (is in proper subtree, is kind of proper page type etc.) just use

 CMS.DocumentEngine.TreeProvider.MoveNodeDown

or

 CMS.DocumentEngine.TreeProvider.MoveNodeUp

depending on your field and ordering requirements.

Upvotes: 3

Related Questions