API
Version 7.x > API > Returning documents in the same order they appear in the CMS content tree View modes: 
User avatar
Member
Member
cormac.debarra-zoorepublic.com - 7/28/2013 11:33:08 PM
   
Returning documents in the same order they appear in the CMS content tree
Hi,

I am trying to retrieve documents from the Kentico API. I am using TreeHelper.GetDocuments(...) and have tried DocumentHelper.GetDocuments(...).

I want the documents to be returned in the same order as the appear in the CMS content tree i.e in a hierarchical fashion.

Is this possible or has anyone achieved something similar.

Thanks

User avatar
Member
Member
Swainy - 7/29/2013 8:42:40 AM
   
RE:Returning documents in the same order they appear in the CMS content tree
Hi,

Yes if you use TreeHelper.GetDocuments() or TreeHelper.SelectNodes() you can pass in an order condition.

If you pass in NodeOrder ASC then this will return them in the order they are in CMS Content tree.

Thanks,

Matt

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/29/2013 8:57:30 AM
   
RE:Returning documents in the same order they appear in the CMS content tree
I've achieved the best results using these three fields: NodeLevel, NodeOrder, NodeName

User avatar
Member
Member
cormac.debarra-zoorepublic.com - 7/29/2013 6:06:14 PM
   
RE:Returning documents in the same order they appear in the CMS content tree
Thanks for the replies.

But unfortunately none of the above work for my situation. Maybe a simple example will explain what I am trying to achieve better.

Consider the following tree.

Parent
---Child1
-------Sub-Child1
---Child2
-------Sub-Child2
Parent1
---Child3
---Child4


I want the returned in the exactly this order i.e
Parent
Child1
Sub-Child1
Child2
Sub-child2
Parent1
Child3
Child4

If I order by NodeLevel,NodeOrder the will be returned in the following order:
Parent
Parent1
Child1
Child3
Child2
Child4
Sub-Child1
Sub-Child2

Can you see my problem now?

Hope someone can help!

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/29/2013 11:40:06 PM
   
RE:Returning documents in the same order they appear in the CMS content tree
The suggestion I gave will return as shown in the content tree by level. If you want a "hierarchical fashion" you will have to create a recursive method in your API call to create that hierarchical effect. As far as I know there isn't a simple order by statement that will display a hierarchical set of pages for you.

User avatar
Member
Member
cormac.debarra-zoorepublic.com - 7/30/2013 1:04:59 AM
   
RE:Returning documents in the same order they appear in the CMS content tree
Thanks.

Thats what I was trying to avoid as it doesn't perform very well when I create the hierarchical tree myself in C# using my recursive function.

I guess I will have to optimize it some other way.

Thanks

User avatar
Member
Member
Swainy - 7/30/2013 1:23:14 PM
   
RE:Returning documents in the same order they appear in the CMS content tree
Hi,

You could use the hierachical viewer web part in Kentico which will give you what you want. Alternatively if it's for navigation then use the css list menu web part.

Thanks,

Matt

User avatar
Member
Member
kentico_sandroj - 7/30/2013 3:01:34 PM
   
RE:Returning documents in the same order they appear in the CMS content tree
Hello,

What are you trying to accomplish with this structure? If you are building a menu, hierarchical viewer would definitely be the your best bet as far as performance and ease-of-use. Nested controls may also work but are not as good for performance. One of the available navigation Web parts may also work.

Please let me know if you have any questions or need additional information.

Regards,
Sandro

User avatar
Member
Member
cormac.debarra-zoorepublic.com - 7/30/2013 9:05:53 PM
   
RE:Returning documents in the same order they appear in the CMS content tree
Thanks,

Yes, its for the main navigation in our site. I have tried a few of the navigation webparts, but we need to add CSS classes for the superfish JS menu library.

I will try the Hierarchical viewer and see if I can achieve it using that web part.