Hi, because getEvent returns a list of items you can sort it and group it.
To get you list you can do something like this.
@foreach (var year in Calendar.getEvents(...).GroupBy(x => x.startDate.Year))
{
@year.Key
foreach(var month in year.GroupBy(x => x.startDate.Month)){
@month.First().startDate.ToString("MMMM")
@foreach(var ce in month){
@ce.content.Name
}
}
}
or like this
@foreach (var items in Calendar.getEvents(...).GroupBy(x => new { x.startDate.Year, x.startDate.Month }))
{
@items.First().startDate.ToString("MMMM yyyy")
foreach (var ce in items)
{
@ce.content.Name
}
}
Your example works awesome as long as I do not try to use the int nodeId parameter in the getEvents call. Example when I do this I get an error:
@foreach (var items in Calendar.getEvents(DateTime.Now.Date, DateTime.Now.AddMonths(2), "calDate", CurrentPage.Id, false).GroupBy(x => new { x.startDate.Year, x.startDate.Month }))
The CurrentPage.Id triggers a dynamic node list which GroupBy pukes on.
I'm trying to use your awesome DataType to allow the customer to insert as many Events Calendar groups as they want. If I take out the CurrentPage.Id (to limit the event list to just each specific section) all the events sections list out all the events on the entire site (not ideal in my case).
Is there a reason why the getEvents call with the int nodeId parameter requires the dynamic node?
Or is there a better way for me to accomplish my goal.
I've tried that. I get this error when I try to use the method that contains the startNode option:
Compiler Error Message: CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
If I take out the startNode option it does not error and pulls in events. I just need it to start from a specific node and not pull from the entire site. I have customers that need multiple calendar/events systems in the same site.
In your source code on GitHub all of the methods return a list EXCEPT for the one asking for a nodeID... that returns a dynamic node... which is causing my lambda expression error. Apparently you cannot do a GroupBy on a dynamic node.
I'm still learning (struggling) with Razor so maybe there's a better way to do what I need... I'm open to suggestions.
Again, thanks for your help and your awesome datatype.
Ole, thanks for trying to help me... I'm still a little stuck (I also updated to the latest version as of this post 0.1.7.5.1)
I tried your code example and I get the following error:
Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments
I also tried this:
List<string> events =...
And I get this error:
'string' does not contain a definition for 'startDate' and no extension method 'startDate' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Group Events by Month/Year etc.
I'm trying to group my events list by month so it looks something like this:
Is this possible to do with the getEvents function?
I have an old event calendar system I wrote many years in XSLT that does this, but I can't figure out how to do this in Razor syntax.
Hi, because getEvent returns a list of items you can sort it and group it. To get you list you can do something like this.
or like this
Ole,
Your example works awesome as long as I do not try to use the int nodeId parameter in the getEvents call. Example when I do this I get an error:
The CurrentPage.Id triggers a dynamic node list which GroupBy pukes on.
I'm trying to use your awesome DataType to allow the customer to insert as many Events Calendar groups as they want. If I take out the CurrentPage.Id (to limit the event list to just each specific section) all the events sections list out all the events on the entire site (not ideal in my case).
Is there a reason why the getEvents call with the int nodeId parameter requires the dynamic node?
Or is there a better way for me to accomplish my goal.
Again, thanks for all your help.
All the methods should return a List
Then you just use CurrentPage instead of CurrentPage.Id
I've tried that. I get this error when I try to use the method that contains the startNode option:
Compiler Error Message: CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Source Error:
If I take out the startNode option it does not error and pulls in events. I just need it to start from a specific node and not pull from the entire site. I have customers that need multiple calendar/events systems in the same site.
In your source code on GitHub all of the methods return a list EXCEPT for the one asking for a nodeID... that returns a dynamic node... which is causing my lambda expression error. Apparently you cannot do a GroupBy on a dynamic node.
I'm still learning (struggling) with Razor so maybe there's a better way to do what I need... I'm open to suggestions.
Again, thanks for your help and your awesome datatype.
Hi, sorry for the late reply. I got this working defining an variable containing the events, and then group the variable.
Ole, thanks for trying to help me... I'm still a little stuck (I also updated to the latest version as of this post 0.1.7.5.1)
I tried your code example and I get the following error:
I also tried this:
And I get this error:
Seems like my answer is rendered wrong inside the pre-tag, the list-type was mistaken as a html-tag.
It shoud be
YES!
That did it. Thank you soooooo much, I really appreciate it.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.