How generate from pagination helper a drop-down list with items per page? Default value is 20 items per page, I want to get something like this:
Show
<select>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
entries
http://jsfiddle.net/HkWuH/
As @BigToach mentioned I have add this to method in my controller
$this->paginate = array(
'paramType' => 'querystring',
'limit' => 30,
'maxLimit' => 100
);
and add following code to my View
$limit = $this->params->query['limit'];
$options = array( 5 => '5', 10 => '10', 20 => '20' );
echo $this->Form->create(array('type'=>'get'));
echo $this->Form->select('limit', $options, array(
'value'=>$limit,
'default'=>20,
'empty' => FALSE,
'onChange'=>'this.form.submit();',
'name'=>'limit'
)
);
echo $this->Form->end();
The results per page is driven by the 'limit' parameter in the paginate array
<?php
$this->paginate = array(
'paramType' => 'querystring',
'limit' => 30,
);
?>
You can override this by setting limit as a query string value. Ex:
?limit=40
From there you just need to build a drop down that changes the URL when they select the number per page.
You might also want to implement maxLimit so users don't change this value to an extremely large number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With