Browse Source

Fixed pagination not working before data loaded

tags/2.0.0-beta
Jin Hu 11 years ago
parent
commit
d9b256d734
  1. 1
      framework/yii/data/DataProvider.php
  2. 17
      tests/unit/framework/data/ActiveDataProviderTest.php

1
framework/yii/data/DataProvider.php

@ -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;
}

17
tests/unit/framework/data/ActiveDataProviderTest.php

@ -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()));
}
}

Loading…
Cancel
Save