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.

Template Questions

How to using GroupedList?


Reply

4 Posts   366 Views

Avatar
anudeepgi

30 January 2014 at 6:38pm (Last edited: 30 January 2014 6:40pm), Community Member, 11 Posts

   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

31 January 2014 at 12:29pm Forum Moderator, 5511 Posts

Is getCarSpeficCatName defined on your car specification model?

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

Avatar
thomas.paulson

31 January 2014 at 3:58pm Community Member, 79 Posts

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

add in car carspecificationscategory model class

Avatar
anudeepgi

31 January 2014 at 7:03pm (Last edited: 31 January 2014 7:05pm), Community Member, 11 Posts

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