mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-20 16:38:22 +08:00
Fixed pagination not working before data loaded
This commit is contained in:
@@ -48,6 +48,7 @@ abstract class DataProvider extends Component implements DataProviderInterface
|
||||
if ($this->id !== null) {
|
||||
$this->_pagination->pageVar = $this->id . '-page';
|
||||
}
|
||||
$this->_pagination->totalCount = $this->getTotalCount();
|
||||
}
|
||||
return $this->_pagination;
|
||||
}
|
||||
|
||||
@@ -85,4 +85,21 @@ class ActiveDataProviderTest extends DatabaseTestCase
|
||||
$provider->refresh();
|
||||
$this->assertEquals(2, count($provider->getModels()));
|
||||
}
|
||||
|
||||
public function testPaginationBeforeModels()
|
||||
{
|
||||
$query = new Query;
|
||||
$provider = new ActiveDataProvider(array(
|
||||
'db' => $this->getConnection(),
|
||||
'query' => $query->from('tbl_order')->orderBy('id'),
|
||||
));
|
||||
$pagination = $provider->getPagination();
|
||||
$this->assertEquals(1, $pagination->getPageCount());
|
||||
$this->assertCount(3, $provider->getModels());
|
||||
|
||||
$provider->getPagination()->pageSize = 2;
|
||||
$this->assertEquals(3, count($provider->getModels()));
|
||||
$provider->refresh();
|
||||
$this->assertEquals(2, count($provider->getModels()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user