Permalink
Browse files

fixed pagination

  • Loading branch information...
1 parent 3d5ff8b commit 13d5238f1562ea547b98b99b94ec502496e78269 @kabturek committed Oct 15, 2011
@@ -11,6 +11,11 @@ public function executeIndex(sfWebRequest $request)
{
$this->setPage($request->getParameter('page'));
}
+ //max per page
+ if ($request->getParameter('rows'))
+ {
+ $this->setMaxPerPage($request->getParameter('rows'));
+ }
if($request->getParameter('_search', false)){
$this->parseSearch($request);
@@ -19,6 +24,7 @@ public function executeIndex(sfWebRequest $request)
$this->pager = $this->getPager();
$this->sort = $this->getSort();
+ // pager
if($request->isXmlHttpRequest()){
$this->setTemplate('jsonIndex');
}
@@ -3,6 +3,7 @@ protected function getPager()
$pager = $this->configuration->getPager('<?php echo $this->getModelClass() ?>');
$pager->setQuery($this->buildQuery());
$pager->setPage($this->getPage());
+ $pager->setMaxPerPage($this->getMaxPerPage());
$pager->init();
return $pager;
@@ -17,6 +18,15 @@ protected function getPage()
{
return $this->getUser()->getAttribute('<?php echo $this->getModuleName() ?>.page', 1, 'admin_module');
}
+ protected function setMaxPerPage($page)
+ {
+ $this->getUser()->setAttribute('<?php echo $this->getModuleName() ?>.per_page', $page, 'admin_module');
+ }
+
+ protected function getMaxPerPage()
+ {
+ return $this->getUser()->getAttribute('<?php echo $this->getModuleName() ?>.per_page', 1, 'admin_module');
+ }
protected function buildQuery()
{
@@ -6,6 +6,6 @@ public function getPagerClass()
public function getPagerMaxPerPage()
{
- return <?php echo isset($this->config['list']['max_per_page']) ? (integer) $this->config['list']['max_per_page'] : 20 ?>;
+ return <?php echo isset($this->config['list']['max_per_page']) ? (integer) $this->config['list']['max_per_page'] : 10 ?>;
<?php unset($this->config['list']['max_per_page']) ?>
}
@@ -19,9 +19,9 @@
$results[$i]['cell'][] = get_partial('<?php echo $this->getModuleName() ?>/list_json_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>, 'helper' => $helper));
}
$ret = array(
- "total" => $pager->getNbResults(),
+ "total" => $pager->getLastPage(),
"page" => $pager->getPage(),
- "records" => count($results),
+ "records" => $pager->getNbResults(),
"rows" => $results,
);
echo json_encode($ret);

0 comments on commit 13d5238

Please sign in to comment.