Copied to clipboard

Flag this post as spam?

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


  • Topic author was deleted

    Jan 14, 2015 @ 17:47

    Sorting DynamicNodeList (after UmbracoExamine search)

    Hi,

    I'm having difficulties in being able to order/sort on names and dates with a DynamicNodeList.

    A bit of background: Search results page. Takes a user query, uses UmbracoExamine to search the content and any PDF documents within media. This works great, and returns results based on relevance.

    A user has the option to sort the results based on the published date or the title. UmbracoExamine.PDFdoesn't store any title/date information for documents, so this isn't possible with the searchResults object that is returned after the search. So, I've pushed the results into a DynamicNodeList object. From here, I'm trying to sort, before looping through (with a foreach) to display the results on the page.

    I've tried a few things: umbNodeList.OrderBy(x => x.GetProperty("title").Value); (we have a separate title field along with the default "name") and umbNodeList.OrderBy("title desc");, but neither of these are working. The first is just ignored (it seems), and the second suggests that there's no definition for the OrderBy function like that.

    Would anyone have any tips on how to resolve this?

  • Alex Skrypnyk 6175 posts 24176 karma points MVP 8x admin c-trib
    Jan 14, 2015 @ 18:20
    Alex Skrypnyk
    0

    Hi Ed,

    Try like that : umbNodeList.Items.OrderBy(x => x.GetProperty("title").Value)

  • Comment author was deleted

    Jan 15, 2015 @ 10:11

    Hi Alex,

    Thanks for the response. I've just tried it with that, and while I'm not getting any errors, it isn't sorting the results either by the looks of things - either on the page or in the list itself?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 15, 2015 @ 12:41
    Jeroen Breuer
    0

    Can you explain why you push the data into a DynamicNodeList? It's a rather old legacy class which was used in Razor in Umbraco 4.7.

    Jeroen

  • Comment author was deleted

    Jan 15, 2015 @ 13:41

    It's just what seemed logical, to get a list of DynamicNode objects from searching around. A more hacky solution I'm implementing at the moment as a work-around is pulling out the title/create date information into separate lists to just sort on those properties, before creating a new node list from the sorted data.

Please Sign in or register to post replies

Write your reply to:

Draft