Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mike Taylor 155 posts 353 karma points
    Nov 05, 2009 @ 00:27
    Mike Taylor
    0

    Given an unsorted array of page IDs, is there a way to retrieve those nodes *in content tree order*?

    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"?

    Thanks,

    Mike

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Nov 05, 2009 @ 09:33
    Thomas Höhler
    0

    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.

    hth, Thomas

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 05, 2009 @ 09:45
    Dirk De Grave
    0

    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.

    Regards,

    /Dirk

  • Mike Taylor 155 posts 353 karma points
    Nov 25, 2009 @ 15:33
    Mike Taylor
    0

    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.

    Mike

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 25, 2009 @ 15:43
    Dirk De Grave
    0

    Cool Mike, looks really nice! Let us know what jquery plugins you've been using, you may get others started!

     

    Cheers,

    /Dirk

  • Mike Taylor 155 posts 353 karma points
    Nov 30, 2009 @ 12:36
    Mike Taylor
    0

    The sorting is done using the standard jQuery UI "Sortable" - http://jqueryui.com/demos/sortable/

Please Sign in or register to post replies

Write your reply to:

Draft