mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #776 from simonwelsh/maniplist
FIX Use the manipulated datalist for counting total items
This commit is contained in:
commit
99ae715f8a
@ -192,6 +192,21 @@ class GridField extends FormField {
|
||||
public function getList() {
|
||||
return $this->list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the datasource after applying the {@link GridField_DataManipulator}s to it.
|
||||
*
|
||||
* @return SS_List
|
||||
*/
|
||||
public function getManipulatedList() {
|
||||
$list = $this->getList();
|
||||
foreach($this->getComponents() as $item) {
|
||||
if($item instanceof GridField_DataManipulator) {
|
||||
$list = $item->getManipulatedData($this, $list);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current GridState_Data or the GridState
|
||||
@ -227,12 +242,7 @@ class GridField extends FormField {
|
||||
$columns = $this->getColumns();
|
||||
|
||||
// Get data
|
||||
$list = $this->getList();
|
||||
foreach($this->getComponents() as $item) {
|
||||
if($item instanceof GridField_DataManipulator) {
|
||||
$list = $item->getManipulatedData($this, $list);
|
||||
}
|
||||
}
|
||||
$list = $this->getManipulatedList();
|
||||
|
||||
// Render headers, footers, etc
|
||||
$content = array(
|
||||
|
@ -108,7 +108,7 @@ class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipu
|
||||
public function getManipulatedData(GridField $gridField, SS_List $dataList) {
|
||||
if(!$this->checkDataType($dataList)) return $dataList;
|
||||
|
||||
$this->totalItems = $gridField->getList()->count();
|
||||
$this->totalItems = $dataList->count();
|
||||
|
||||
$state = $gridField->State->GridFieldPaginator;
|
||||
if(!is_int($state->currentPage)) {
|
||||
|
@ -392,6 +392,22 @@ class GridFieldTest extends SapphireTest {
|
||||
$this->assertEquals((string)$members[1]->td[0], 'Otto Fischer', 'Second object Name should be Otto Fischer');
|
||||
$this->assertEquals((string)$members[1]->td[1], 'otto.fischer@example.org', 'Second object Email should be otto.fischer@example.org');
|
||||
}
|
||||
|
||||
public function testChainedDataManipulators() {
|
||||
$config = new GridFieldConfig();
|
||||
$data = new ArrayList(array(1, 2, 3, 4, 5, 6));
|
||||
$gridField = new GridField('testfield', 'testfield', $data, $config);
|
||||
$endList = $gridField->getManipulatedList();
|
||||
$this->assertEquals($endList->Count(), 6);
|
||||
|
||||
$config->addComponent(new GridFieldTest_Component2);
|
||||
$endList = $gridField->getManipulatedList();
|
||||
$this->assertEquals($endList->Count(), 12);
|
||||
|
||||
$config->addComponent(new GridFieldPaginator(10));
|
||||
$endList = $gridField->getManipulatedList();
|
||||
$this->assertEquals($endList->Count(), 10);
|
||||
}
|
||||
}
|
||||
|
||||
class GridFieldTest_Component implements GridField_ColumnProvider, GridField_ActionProvider, TestOnly{
|
||||
@ -430,6 +446,14 @@ class GridFieldTest_Component implements GridField_ColumnProvider, GridField_Act
|
||||
|
||||
}
|
||||
|
||||
class GridFieldTest_Component2 implements GridField_DataManipulator, TestOnly {
|
||||
function getManipulatedData(GridField $gridField, SS_List $dataList) {
|
||||
$dataList = clone $dataList;
|
||||
$dataList->merge(new ArrayList(array(7, 8, 9, 10, 11, 12)));
|
||||
return $dataList;
|
||||
}
|
||||
}
|
||||
|
||||
class GridFieldTest_Team extends DataObject implements TestOnly {
|
||||
static $db = array(
|
||||
'Name' => 'Varchar',
|
||||
|
Loading…
Reference in New Issue
Block a user