Commit 647aa71a by Qiang Xue

Merge pull request #909 from bixuehujin/dataprovider

Fixed pagination not working before data loaded
parents 220db270 b7948e48
......@@ -156,7 +156,6 @@ class ActiveDataProvider extends DataProvider
throw new InvalidConfigException('The "query" property must be an instance of Query or its subclass.');
}
if (($pagination = $this->getPagination()) !== false) {
$pagination->totalCount = $this->getTotalCount();
$this->query->limit($pagination->getLimit())->offset($pagination->getOffset());
}
if (($sort = $this->getSort()) !== false) {
......
......@@ -114,7 +114,6 @@ class ArrayDataProvider extends DataProvider
}
if (($pagination = $this->getPagination()) !== false) {
$pagination->totalCount = $this->getTotalCount();
$models = array_slice($models, $pagination->getOffset(), $pagination->getLimit());
}
......
......@@ -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()));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment