Copied to clipboard

Flag this post as spam?

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


  • Rajeev 126 posts 154 karma points
    Aug 10, 2011 @ 12:27
    Rajeev
    0

    Group by Month and Year

    I have a list of Contents with Document Type having on of the property as Date Picker, I would like to display the contents grouped together  by Month,Year. Could any one please let me know a way to do this using Razor script.

    Appreciate your inputs.

    -Rajeev

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Aug 12, 2011 @ 16:42
    Dan Diplo
    0

    Could you give an example of the output you would like to see?

  • Rajeev 126 posts 154 karma points
    Aug 13, 2011 @ 07:30
    Rajeev
    0

    Hi Dan,

    I have a Document type with Data type as DatePicker as a start date(Like an Event).
    The document type has additional properties like Title, Image, Description etc..
    I need to list out those based on Month and Year. current Month + 5 Months.

    First thing I think I need to Get the Informaton in a list like this

    August 2011  Item1Title ItemDesc ItemImage
    August 2011  Item2Title ItemDesc ItemImage
    September 2011  Item1Title ItemDesc ItemImage
    September 2011  Item2Title ItemDesc ItemImage
    October 2011 Item1Title ItemDesc ItemImage
    October 2011  Item2Title ItemDesc ItemImage


    Then I will list that under

    August 2011
       Item1.....
       Item2.....

    September 2011
     Item1....
     Item2....
    Octpber 2011
     Item1....
     Item2....

    I am facing some problems with manipulating datepicker value in Razor like we do in LINQ or SQL.

    Hope the question is clear now.

    Appreciate your help.

    Thanks,
    Rajeev

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Aug 15, 2011 @ 10:49
    Dan Diplo
    0

    Hi Rajeev,

    OK, I can at least help you with the first part, which is the initial listing for the next 5 months. Assuming your event date property is called DisplayDate then you could do this:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        var nodes = Model.Descendants().Where("Visible")
            .OrderBy("DisplayDate")
            .Where("DisplayDate > DateTime.Now.Date && DisplayDate < DateTime.Now.Date.AddMonths(5)");
    
        <ul>
        @foreach (var item in nodes)
        {
            <li>
               @item.DisplayDate.ToString("MMMM yyyy") : @item.Name
            </li>
        }
        </ul>
    }

    The second part is more tricky. The way I would have done it in using standard LINQ queries doesn't work with Umbraco. If I get some time I'll have a think and see if there's another way that does work.

  • Rajeev 126 posts 154 karma points
    Aug 15, 2011 @ 13:23
    Rajeev
    0

    Hi Dan,

    Thank you for the reply. I really appreciate that. I will update once I start working on this...

    Thank you again,

    Rajeev

  • Rajeev 126 posts 154 karma points
    Sep 15, 2011 @ 15:16
    Rajeev
    1

    I have modified the foreach section as following  to achieve this.

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{

    //current month value to compare
    string monthYear=String.Empty;

    var nodes =Model.Descendants().Where("Visible")
    .OrderBy("displayDate")
    .Where("displayDate >= DateTime.Now.Date && displayDate < DateTime.Now.Date.AddMonths(5)");

     @foreach (var item in nodes)
       
    {


     

     //if the month changed to another month then display monthyear header
     @if(!monthYear.Equals(item.displayDate.ToString("MMMM yyyy")))

          
     {
          
     

          
             monthYear=item.displayDate.ToString("MMMM yyyy");
     
           

    @monthYear


     


     }

            @item.title

            @item.description
           

    }

    }

    Thank you Dan again for your help.

    Rajeev

  • siva kumar 120 posts 209 karma points
    Nov 08, 2012 @ 11:18
    siva kumar
    0

    hi

    how can i achieve above in jsonstring

    nov 2012

    event related data

    dec 2012

    event related data

  • siva kumar 120 posts 209 karma points
    Nov 09, 2012 @ 10:50
    siva kumar
    0

    hi

    above where condition is not wotking in 4.7.1.1 how to rectify it.

Please Sign in or register to post replies

Write your reply to:

Draft