mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '3'
This commit is contained in:
commit
f3b6bb1470
@ -212,17 +212,22 @@ class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipu
|
||||
return null;
|
||||
}
|
||||
|
||||
$totalPages = (int)ceil($totalRows/$this->itemsPerPage);
|
||||
if ($totalPages == 0) {
|
||||
$totalPages = 1;
|
||||
}
|
||||
$firstShownRecord = ($state->currentPage - 1) * $this->itemsPerPage + 1;
|
||||
if ($firstShownRecord > $totalRows) {
|
||||
$firstShownRecord = $totalRows;
|
||||
}
|
||||
$lastShownRecord = $state->currentPage * $this->itemsPerPage;
|
||||
if ($lastShownRecord > $totalRows) {
|
||||
$lastShownRecord = $totalRows;
|
||||
$totalPages = 1;
|
||||
$firstShownRecord = 1;
|
||||
$lastShownRecord = $totalRows;
|
||||
if ($itemsPerPage = $this->getItemsPerPage()) {
|
||||
$totalPages = (int)ceil($totalRows / $itemsPerPage);
|
||||
if ($totalPages == 0) {
|
||||
$totalPages = 1;
|
||||
}
|
||||
$firstShownRecord = ($state->currentPage - 1) * $itemsPerPage + 1;
|
||||
if ($firstShownRecord > $totalRows) {
|
||||
$firstShownRecord = $totalRows;
|
||||
}
|
||||
$lastShownRecord = $state->currentPage * $itemsPerPage;
|
||||
if ($lastShownRecord > $totalRows) {
|
||||
$lastShownRecord = $totalRows;
|
||||
}
|
||||
}
|
||||
|
||||
// If there is only 1 page for all the records in list, we don't need to go further
|
||||
|
@ -291,8 +291,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
/**
|
||||
* Construct a new DataObject.
|
||||
*
|
||||
* @param array|null $record This will be null for a new database record. Alternatively, you can pass an array of
|
||||
* field values. Normally this constructor is only used by the internal systems that get objects from the database.
|
||||
|
||||
* @param array|null $record Used internally for rehydrating an object from database content.
|
||||
* Bypasses setters on this class, and hence should not be used
|
||||
* for populating data on new records.
|
||||
* @param boolean $isSingleton This this to true if this is a singleton() object, a stub for calling methods.
|
||||
* Singletons don't have their defaults set.
|
||||
* @param DataModel $model
|
||||
|
@ -2,46 +2,46 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests\GridField;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||
use SilverStripe\Forms\GridField\GridFieldPageCount;
|
||||
use SilverStripe\Forms\GridField\GridFieldPaginator;
|
||||
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
|
||||
use SilverStripe\Forms\GridField\GridFieldPaginator;
|
||||
use SilverStripe\Forms\GridField\GridFieldPageCount;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
|
||||
class GridFieldPaginatorTest extends FunctionalTest
|
||||
{
|
||||
/**
|
||||
* @var ArrayList
|
||||
*/
|
||||
* @var ArrayList
|
||||
*/
|
||||
protected $list;
|
||||
|
||||
/**
|
||||
* @var GridField
|
||||
*/
|
||||
* @var GridField
|
||||
*/
|
||||
protected $gridField;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
* @var string
|
||||
*/
|
||||
protected static $fixture_file = 'GridFieldTest.yml';
|
||||
|
||||
/**
|
||||
* @var Form
|
||||
*/
|
||||
* @var Form
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
* @var array
|
||||
*/
|
||||
protected $extraDataObjects = array(
|
||||
Team::class,
|
||||
Player::class
|
||||
@ -87,6 +87,27 @@ class GridFieldPaginatorTest extends FunctionalTest
|
||||
$this->assertEquals(2, count($content->getBySelector('.pagination-records-number')));
|
||||
}
|
||||
|
||||
public function testUnlimitedRowCount()
|
||||
{
|
||||
$total = $this->list->count();
|
||||
// set up the paginator
|
||||
/** @var GridFieldPaginator $paginator */
|
||||
$paginator = $this->gridField->getConfig()->getComponentByType(GridFieldPaginator::class);
|
||||
$paginator->setThrowExceptionOnBadDataType(true);
|
||||
$paginator->setItemsPerPage(1);
|
||||
$paginator->getManipulatedData($this->gridField, $this->list);
|
||||
|
||||
|
||||
$params = $paginator->getTemplateParameters($this->gridField)->toMap();
|
||||
$this->assertFalse($params['OnlyOnePage']);
|
||||
$this->assertEquals($total, $params['NumRecords']);
|
||||
|
||||
$paginator->setItemsPerPage(0);
|
||||
$params = $paginator->getTemplateParameters($this->gridField)->toMap();
|
||||
$this->assertTrue($params['OnlyOnePage']);
|
||||
$this->assertEquals($total, $params['NumRecords']);
|
||||
}
|
||||
|
||||
public function testPaginationAvoidsIllegalOffsets()
|
||||
{
|
||||
$grid = $this->gridField;
|
||||
|
Loading…
Reference in New Issue
Block a user