3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 755 Views |
-
GroupBy is not supported in DataList for SilverStripe 3 ?

13 May 2012 at 10:47am
Hi there,
I am struggling to convert the code below from the tutorial (http://doc.silverstripe.org/sapphire/en/tutorials/3-forms) to Silverstripe 3. I understand using DataList is a recommend approach and DataObjectSet is depreciated, but it seems that Group By is not supported in DataList.
Anyone has idea how to make the code working using SilverStripe 3’s new ORM like http://www.silverstripe.org/silverstripe-3-s-new-orm/ ?function BrowserPollResults() {
$submissions = DataObject::get('BrowserPollSubmission');
$total = $submissions->Count();$doSet = new DataObjectSet();
foreach($submissions->groupBy('Browser') as $browser => $data) {
$percentage = (int) ($data->Count() / $total * 100);
$record = array(
'Browser' => $browser,
'Percentage' => $percentage
);
$doSet->push(new ArrayData($record));
}return $doSet;
} -
Re: GroupBy is not supported in DataList for SilverStripe 3 ?

25 June 2012 at 11:28am
Hey,
for simmilar functionality you can use GroupedList:
$groupedSubmissionsList = new GroupedList($submissions);
$grouped = $groupedSubmissionsList->groupBy("Browser");Cheers
| 755 Views | ||
|
Page:
1
|
Go to Top |

