Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » GroupBy is not supported in DataList for SilverStripe 3 ?

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

Page: 1
Go to End
Author Topic: 1652 Views
  • Phat
    Avatar
    Community Member
    8 Posts

    GroupBy is not supported in DataList for SilverStripe 3 ? Link to this post

    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;
    }

  • t|m
    Avatar
    Community Member
    19 Posts

    Re: GroupBy is not supported in DataList for SilverStripe 3 ? Link to this post

    Hey,

    for simmilar functionality you can use GroupedList:

    $groupedSubmissionsList = new GroupedList($submissions);
    $grouped = $groupedSubmissionsList->groupBy("Browser");

    Cheers

    1652 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.