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
I have tried to get this to work several ways but it just seems not to work.
@{ var selection = Umbraco.Content(Guid.Parse("4cc0a5b1-010f-406f-9d72-2689074b8142")) .Children() .Where(x => x.IsVisible()) .OrderByDescending(x => x.HasValue("newsPublishedDate"));
} @foreach (var item in selection) {
</div>
}
Previously I have also used
@foreach(var item in selection.OrderBy("newsPublishedDate")){
But neither sorts the items by the date picker "newsPublishedDate"
Does any one have any ideas?
Hi Mark,
I think your first option is the closest but your OrderBy Descending is an issue.
.OrderByDescending(x => x.HasValue("newsPublishedDate")
HasValue returns true or false, so assuming they all have a date then its sorting on "true" for everything.
What you probably want is:
.OrderByDescending(x => x.Value<DateTime>("newsPublishedDate")
Something to consider, what do you want it to do when multiple items have the same newsPublishedDate ?
Maybe something like this?
.OrderByDescending(x => x.Value<DateTime>("newsPublishedDate").ThenBy(x=>x.SortOrder)
Disclaimer: I can't recall the exact syntax for the ThenBy bit but I think that is right.
Thanks
Nik
Thanks Nik. Worked perfectly Yes the syntax is correct
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Date picker sort order not working
I have tried to get this to work several ways but it just seems not to work.
} @foreach (var item in selection) {
@item.Name
}
Previously I have also used
But neither sorts the items by the date picker "newsPublishedDate"
Does any one have any ideas?
Hi Mark,
I think your first option is the closest but your OrderBy Descending is an issue.
HasValue returns true or false, so assuming they all have a date then its sorting on "true" for everything.
What you probably want is:
Something to consider, what do you want it to do when multiple items have the same newsPublishedDate ?
Maybe something like this?
Disclaimer: I can't recall the exact syntax for the ThenBy bit but I think that is right.
Thanks
Nik
Thanks Nik. Worked perfectly Yes the syntax is correct
is working on a reply...