mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API Create a new GridFieldLazyLoader GridField component
This commit is contained in:
parent
1d1cf6882d
commit
bdb53979aa
47
src/Forms/GridField/GridFieldLazyLoader.php
Executable file
47
src/Forms/GridField/GridFieldLazyLoader.php
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Forms\GridField;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\ArrayList;
|
||||||
|
use SilverStripe\ORM\SS_List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GridFieldLazyLoader alters the {@link GridField} behavior to delay rendering of rows until the tab containing the
|
||||||
|
* GridField is selected by the user.
|
||||||
|
*
|
||||||
|
* @see GridField
|
||||||
|
*/
|
||||||
|
class GridFieldLazyLoader implements GridField_DataManipulator, GridField_HTMLProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getManipulatedData(GridField $gridField, SS_List $dataList)
|
||||||
|
{
|
||||||
|
return $this->isLazy($gridField) ?
|
||||||
|
ArrayList::create([]) :
|
||||||
|
$dataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getHTMLFragments($gridField)
|
||||||
|
{
|
||||||
|
$gridField->addExtraClass($this->isLazy($gridField) ?
|
||||||
|
'grid-field-lazy-loadable' :
|
||||||
|
'grid-field-lazy-loaded');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect if the current request should include results
|
||||||
|
* @param GridField $gridField
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isLazy(GridField $gridField)
|
||||||
|
{
|
||||||
|
return $gridField->getRequest()->getHeader('X-Pjax') !== 'CurrentField';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user