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   468 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, 5513 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, 86 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