Skip to content

Commit

Permalink
fixed pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
kabturek committed Oct 15, 2011
1 parent 3d5ff8b commit 13d5238
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions data/generator/sfDoctrineModule/jqgrid/parts/indexAction.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public function executeIndex(sfWebRequest $request)
{ {
$this->setPage($request->getParameter('page')); $this->setPage($request->getParameter('page'));
} }
//max per page
if ($request->getParameter('rows'))
{
$this->setMaxPerPage($request->getParameter('rows'));
}


if($request->getParameter('_search', false)){ if($request->getParameter('_search', false)){
$this->parseSearch($request); $this->parseSearch($request);
Expand All @@ -19,6 +24,7 @@ public function executeIndex(sfWebRequest $request)


$this->pager = $this->getPager(); $this->pager = $this->getPager();
$this->sort = $this->getSort(); $this->sort = $this->getSort();
// pager
if($request->isXmlHttpRequest()){ if($request->isXmlHttpRequest()){
$this->setTemplate('jsonIndex'); $this->setTemplate('jsonIndex');
} }
Expand Down
10 changes: 10 additions & 0 deletions data/generator/sfDoctrineModule/jqgrid/parts/paginationAction.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ protected function getPager()
$pager = $this->configuration->getPager('<?php echo $this->getModelClass() ?>'); $pager = $this->configuration->getPager('<?php echo $this->getModelClass() ?>');
$pager->setQuery($this->buildQuery()); $pager->setQuery($this->buildQuery());
$pager->setPage($this->getPage()); $pager->setPage($this->getPage());
$pager->setMaxPerPage($this->getMaxPerPage());
$pager->init(); $pager->init();


return $pager; return $pager;
Expand All @@ -17,6 +18,15 @@ protected function getPage()
{ {
return $this->getUser()->getAttribute('<?php echo $this->getModuleName() ?>.page', 1, 'admin_module'); 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() protected function buildQuery()
{ {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public function getPagerClass()


public function getPagerMaxPerPage() 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']) ?> <?php unset($this->config['list']['max_per_page']) ?>
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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)); $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( $ret = array(
"total" => $pager->getNbResults(), "total" => $pager->getLastPage(),
"page" => $pager->getPage(), "page" => $pager->getPage(),
"records" => count($results), "records" => $pager->getNbResults(),
"rows" => $results, "rows" => $results,
); );
echo json_encode($ret); echo json_encode($ret);

0 comments on commit 13d5238

Please sign in to comment.