I'm grouping a list of items by a date type property, which is working great. However, inside the initial group, I'm looking to add a header with the day of the group, I can't seem to access any properties of the group.
Any ideas (code below)?
Thanks!
Amir
@foreach(var itemGroup in selection.OrderBy("startDateAndTime").Skip((page -1)* pageSize).Take(pageSize).GroupBy("startDateAndTime.Day")) {
<h1>@itemGroup.startDateAndTime.Day</h1> how do i get the date here!?
foreach(var item in itemGroup) {
@item.Name
}
Okay, changing selection to iPublishedContent by using Model.Content instead of CurrentPage allowed me to get @itemGroup.Key to work, but I still can't access any other properties? I can only get the group by day and not the year.
Is there a way to access the properties of the group or even an item in it?
I want to group items by day, add a heading for each day above the items, then iterate through the items. I want to heading to have day/month, hence the need to access more than just the key.
@foreach(var itemGroup in selection.OrderBy("startDateAndTime").Skip((page -1)* pageSize).Take(pageSize)) {
var group = new DateTime();
if(group!=itemGroup.GetPropertyValue<DateTime>("startDateAndTime")){
<h1>@itemGroup.startDateAndTime.Day</h1>
}
group = itemGroup.GetPropertyValue<DateTime>("startDateAndTime");
@itemGroup.Name
Access property after grouping
Hi!
I'm grouping a list of items by a date type property, which is working great. However, inside the initial group, I'm looking to add a header with the day of the group, I can't seem to access any properties of the group.
Any ideas (code below)?
Thanks!
Amir
}
what is selection? is selection ipublishedcontent? then you can "itemgroup.GetpropertyValue< DateTime >("startdate").Day"
You can do this I think :
Haven't actually tried this code, but should work
Dave
Yasir, selection is Umbraco.Web.Models.DynamicPublishedContentList
itemGroup is Umbraco.Web.Dynamics.Grouping`2[System.Object,Umbraco.Web.Models.DynamicPublishedContent]
Unfortunately both of the above suggestions return " 'object' does not contain a definition for..."
Any ideas?
-Amir
Okay, changing selection to iPublishedContent by using Model.Content instead of CurrentPage allowed me to get @itemGroup.Key to work, but I still can't access any other properties? I can only get the group by day and not the year.
Is there a way to access the properties of the group or even an item in it?
Thanks!
Amir
Have you tried
itemgroup.GetpropertyValue("yourproperty")
?Yep, get this: CS1928: 'System.Linq.IGrouping
why are you using groupby? can you not use this without groupby?
I want to group items by day, add a heading for each day above the items, then iterate through the items. I want to heading to have day/month, hence the need to access more than just the key.
-Amir
ok!
it can be achieve like this.
Hi Yasir, the grouping here just pulls the day for each item, not for the group.
I'm trying to actually access properties of the group like:
Group Date - group item - group item - group item
Group 2 Date - group 2 item - group 2 item - group 2 item
Is there a way maybe to just insert something before the first item in the group? -Amir
Inserting something before the first item worked perfectly.
Here's what I ended up with:
ok! have you solved it?
Now i noticed one thing in my code
if you just put the
Before loop then it should work as you want to.
is working on a reply...