Copied to clipboard

Flag this post as spam?

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


  • Andrew Cullen 137 posts 237 karma points
    Jun 17, 2014 @ 16:12
    Andrew Cullen
    0

    OrderBy datepicker property not working as expected

    I have the following code:

    var selection= CurrentPage.Parent.Events.Where("Visible==true && EventType == \"" + eventType + "\"").OrderBy("StartDate descending")
    

    The problem is, the OrderBy seems to be treating StartDate as a string instead of a date - for example, March dates show up before May dates despite the "descending". Any tricks to make the OrderBy treat a datepicker value as a date?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 17, 2014 @ 16:14
    Jeavon Leopold
    100

    Hi Andrew,

    Should be like this:

    .OrderBy("StartDate desc")  
    

    Hope that fixes it for you?

    Jeavon

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 17, 2014 @ 16:17
    Jeavon Leopold
    1

    You could also improve your .Where slightly, e.g.

    var selection = CurrentPage.Parent.Events.Where("Visible && EventType == @0", eventType).OrderBy("StartDate desc");                
    

    Jeavon

  • Andrew Cullen 137 posts 237 karma points
    Jun 17, 2014 @ 17:19
    Andrew Cullen
    0

    Oh, good Lord, how embarrassing.

    And thanks for the syntax improvement; I didn't know you could parameterize that way!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 17, 2014 @ 17:23
    Jeavon Leopold
    0

    No worries, with dynamics you have no idea what the problem is :-)

  • Andrew Cullen 137 posts 237 karma points
    Sep 05, 2014 @ 16:48
    Andrew Cullen
    0

    Hmmm, this is odd. I'm running into the same issue again in a different partial view, where the sort order appears to be treating the datepicker property as a string. Any suggestions on how to fix this?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 05, 2014 @ 16:51
    Jeavon Leopold
    0

    If the data property you are ordering by is of data picker, then it should be ok. Could you post your new code snippet?

Please Sign in or register to post replies

Write your reply to:

Draft