mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT: Allow nested grouping of GroupedList
This commit is contained in:
parent
dbb6ba82f8
commit
6676787176
@ -43,6 +43,7 @@ class GroupedList extends SS_ListDecorator {
|
||||
$result = new ArrayList();
|
||||
|
||||
foreach ($grouped as $indVal => $list) {
|
||||
$list = GroupedList::create($list);
|
||||
$result->push(new ArrayData(array(
|
||||
$index => $indVal,
|
||||
$children => $list
|
||||
|
@ -49,4 +49,78 @@ class GroupedListTest extends SapphireTest {
|
||||
$this->assertEquals('CCC', $last->Name);
|
||||
}
|
||||
|
||||
public function testGroupedByChildren(){
|
||||
$list = GroupedList::create(
|
||||
ArrayList::create(
|
||||
array(
|
||||
ArrayData::create(array(
|
||||
'Name' => 'AAA',
|
||||
'Number' => '111',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'BBB',
|
||||
'Number' => '111',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'AAA',
|
||||
'Number' => '222',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'BBB',
|
||||
'Number' => '111',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'AAA',
|
||||
'Number' => '111',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'AAA',
|
||||
'Number' => '333',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'BBB',
|
||||
'Number' => '222',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'BBB',
|
||||
'Number' => '333',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'AAA',
|
||||
'Number' => '111',
|
||||
)),
|
||||
ArrayData::create(array(
|
||||
'Name' => 'AAA',
|
||||
'Number' => '333',
|
||||
))
|
||||
)
|
||||
)
|
||||
);
|
||||
$grouped = $list->GroupedBy('Name');
|
||||
|
||||
foreach($grouped as $group){
|
||||
$children = $group->Children;
|
||||
$childGroups = $children->GroupedBy('Number');
|
||||
|
||||
$this->assertEquals(3, count($childGroups));
|
||||
|
||||
$first = $childGroups->first();
|
||||
$last = $childGroups->last();
|
||||
|
||||
if($group->Name == 'AAA'){
|
||||
$this->assertEquals(3, count($first->Children));
|
||||
$this->assertEquals('111', $first->Number);
|
||||
$this->assertEquals(2, count($last->Children));
|
||||
$this->assertEquals('333', $last->Number);
|
||||
}
|
||||
|
||||
if($group->Name == 'BBB'){
|
||||
$this->assertEquals(2, count($first->Children));
|
||||
$this->assertEquals('111', $first->Number);
|
||||
$this->assertEquals(1, count($last->Children));
|
||||
$this->assertEquals('333', $last->Number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user