Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
On my site, I have a "print basket" function where visitors can add the page they're viewing to a "print basket". The front-end to this is a jQuery function which just writes a pipe-separated list of Umbraco page IDs to a cookie (eg "1080|1094|1079|1095|1103|1083"). The order of the IDs in this list is the order in which the pages are added by the user.
Once they've collected all the pages they're interested in, they can view their "basket", and print out the content from all the selected pages in one go. Collecting the content from a series of nodes isn't a problem, but I'd really like the content to be displayed in the same logical order in which it appears on the site, ie the order in which it appears in the content tree.
This could be done by traversing every node, and checking to see if its ID is contained in the cookie, but this would be massively inefficient. Is there a clean, reasonably efficient way I can retrieve the nodes in "content tree order"?
It depends on the structure. if the nodes are all subnodes from one node it is really simple:
via xslt you can sort by the attribute node/@sortOrder
<xsl:for-each select="..."> <xsl:sort select="@sortOrder" order="ascending" />
and in umbraco.presentation.nodeFactory.Node you have the property SortOrder. When you put these nodes into one array you can easily sort with LinQ
If the nodes are subnodes from several nodes in a hierachy this will get a little bit more difficult but also possible depending on how your structure is.
Agree with Thomas, sorting is easy if nodes are all subnodes of the same parent node, otherwise, a bit more logic is required (and will involve some coding I'm afraid)
On the sidenote, why don't you let the user decide in which order to print (do they ever know about your content structure)? It can be done client side using some jquery and you don't have to do any additional server coding! You just take the sort order from the client and start printing the 'page basket'
Hope this helps.
Thanks both for your help.
Having given it some more thought, I think you're right, Dirk - the user should be able to sort the pages themselves. I took your advice and added some jQuery magic to allow the user to sort the pages and I think it works well.
Here's a quick screencast, if you're interested:http://screencast.com/t/Y2ZhMmY3Nz
Thanks again, much appreciated.
Cool Mike, looks really nice! Let us know what jquery plugins you've been using, you may get others started!
The sorting is done using the standard jQuery UI "Sortable" - http://jqueryui.com/demos/sortable/
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted