Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Nested Grouped Lists

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 431 Views
  • cumquat
    Avatar
    Community Member
    196 Posts

    Nested Grouped Lists Link to this post

    Hi there,

    I'm trying to create a grouped list with two groupings, im using 3.1 and i have it working lovely with just one grouping but for the life of me i cant figure out how to make it two groupings.
    The table has a number of columns one called stage the other called category and i'd like to list all records by stage then within each stage by category.

    below is my code from the dataobject and on the template.

    hope you can help.

    Mick

    <div class="checklist">
                      <% loop groupedChecks.GroupedBy(Stage) %>
                      <div class="row ">
                         <div class="large-12 columns field">
                            <h5>$Stage</h5>
                         </div>
                      </div>
                         <% loop Children %>
                            <div class="row">
                               <div class="large-12 columns ">
                                  <div class="large-9 columns field">
                                     <p>$Name</p>
                                  </div>
                                  <% if Checked %>
                                      <div class="large-3 columns field">
                                        <div class="roundedOne">
                                           <input type="checkbox" value="0" id="roundedOne $ID" name="$ID" checked="checked" />
                                           <label for="roundedOne $ID"></label>
                                        </div>
                                     </div>
                                  <% else %>
                                     <div class="large-3 columns field">
                                        <div class="roundedOne">
                                           <input type="checkbox" value="1" id="roundedOne $ID" name="$ID" />
                                           <label for="roundedOne $ID"></label>
                                        </div>
                                     </div>
                                  <% end_if %>
                               </div>
                            </div>
                         <% end_loop %>
                      <% end_loop %>
                   </div>


    function groupedChecks() {
    return GroupedList::create(TheCheck::get()->filter('ProjectID' , $this->ID));
    }

  • cumquat
    Avatar
    Community Member
    196 Posts

    Re: Nested Grouped Lists Link to this post

    **bump** anyone?

    Im sure in 2.4 you could also then group on the child loop so in this case it would be.
    as in this example http://www.silverstripe.org/general-questions/show/9070

    <% loop groupedChecks.GroupedBy(Stage) %>
       <div class="row ">
       <div class="large-12 columns field">
          <h5>$Stage</h5>
       </div>
       </div>
          <% loop Children.GroupedBy(Category) %>
    <h5>$Category</h5>
             <% loop Children %>
    <div class="row">
                <div class="large-12 columns ">
                   <div class="large-9 columns field">
                      <p>$Name</p>
                   </div>
    </div>
    </div>
    <% end_loop %>
    <% end_loop %>
    <% end_loop %>

  • RobboDev
    Avatar
    Community Member
    20 Posts

    Re: Nested Grouped Lists Link to this post

    Hey Bro,

    Just done this. See attached file "NestedGroupedList" only allows 2 levels of nesting, cos i couldn't be arsed to do "infinite" levels.

    With it you can group by 2 different aspects of the data object, first return the list in your function:

    public function GroupedEntries() {
    return NestedGroupedList::create(
       BlogEntry::get()->sort('Year DESC, Month ASC')
    );
    }

    Then in your template, separate the 2 different groupings with a comma:

    <% loop $GroupedEntries.GroupedBy('Year,Month') %>
           <h3>$Year</h3>
           <ul>
           <% loop $Children %>
           <h3>$Month</h3>
           <ul>
                 <% loop $Children %>
                 <li>$Title</li>
                 <% end_loop %>
                 </ul>
           <% end_loop %>
           </ul>
          <% end_loop %>

    NB: this wont work for a default blog entry unless you extended yours with the year and month fields.

    Chur BOI!

    Attached Files
    431 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.