Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

How to using GroupedList?


Go to End


5 Posts   3816 Views

Avatar
anudeepgi

Community Member, 11 Posts

30 January 2014 at 6:38pm

Edited: 30/01/2014 6:40pm

function subraya(){
return GroupedList::create(carspecification::get()->leftJoin("carspecificationscategory", "\"carspecificationscategory\".\"ID\" = \"carspecification\".\"CarSpecificationsCategoryID\"")->filter(array('CarsID' => $this->CarsID,'CarSpecificationsTypeID' => '4')));
}

<% loop $subraya.GroupedBy(CarSpecificationsCategoryID) %>
<h3>$getCarSpeficCatName.Title</h3>
<ul>
<% loop $Children %>
<li>$Title </li>
<% end_loop %>
</ul>
<% end_loop %>

What is the issue with this code everthing works properly but '$getCarSpeficCatName.Title' is not displaying anything

Please help me..

Avatar
Willr

Forum Moderator, 5523 Posts

31 January 2014 at 12:29pm

Is getCarSpeficCatName defined on your car specification model?

See the examples at http://doc.silverstripe.org/framework/en/howto/grouping-dataobjectsets

Avatar
thomas.paulson

Community Member, 107 Posts

31 January 2014 at 3:58pm

public function getCarSpeficCatName () {
return $this->Title;
}

add in car carspecificationscategory model class

Avatar
anudeepgi

Community Member, 11 Posts

31 January 2014 at 7:03pm

Edited: 31/01/2014 7:05pm

What i want is Group based on Category ,

CarSpecificationsPage.php

function subraya(){
return GroupedList::create(carspecification::get()->leftJoin("carspecificationscategory", "\"carspecificationscategory\".\"ID\" = \"carspecification\".\"CarSpecificationsCategoryID\"")->filter(array('CarsID' => $this->CarsID,'CarSpecificationsTypeID' => '4')));
}
I am querying join 2 table one 'carspecification' other one is 'carspecificationscategory' table

carspecification table is have this feilds
ID
ClassName
Created
LastEdited
Title
CarSpecificationsCategoryID
CarSpecificationsTypeID
Title Value
CarsID
TitleValue

carspecificationscategory
ID
ClassName
Created
LastEdited
Title

i need something like in view

CategoryTitle1 - this from carspecificationscategory
Title1 - this from carspecification
title2 - this from carspecification
CategoryTitle2 - this from carspecificationscategory
Title1 - this from carspecification
title2 - this from carspecification

<% loop $subraya.GroupedBy(CarSpecificationsCategoryID) %>
<h3>$carspecificationscategory.Title</h3>
<ul>
<% loop $Children %>
<li>$Title </li>
<% end_loop %>
</ul>
<% end_loop %>

is ther any easy way to achieve this please explain

Avatar
Robby

Community Member, 3 Posts

8 January 2016 at 12:08pm

I have a similar issue to sort out. Hope this is useful

-My first approach was create ArrayList including grouped information
$youritems = new ArrayList();
$youritems->push(new ArrayData( array('title' => myTitle, 'category' => groupA)))

-Then create GroupedList based on your ArrayList
GroupedList::create($youritems->sort('category'));

Then display on your template

<% loop youritems %>
<% loop $Children %>
$title
<% end_loop %>
<% end_loop %>