zfdatagrid / grid

A DataGrid library for Zend Framework
BSD 3-Clause "New" or "Revised" License
10 stars 16 forks source link

showing all records using the setRecordsPerPage method does not work when a start value is present #894

Open danhammari opened 10 years ago

danhammari commented 10 years ago

When showing all records in a grid, shouldn't the grid ignore the record start value? I have added a pagination control to the grid so a user can select the number of items to show per page. This pagination control includes the value zero, which should show all records. However, if a user selects the zero value on the pagination control when not on the first page of the grid, the start value is retained and the grid shows all records except for those that occurred before the start value.

$per_page = Zend_Controller_Front::getInstance()->getRequest()->getParam('perPage',false);
if($per_page !== false){
    $grid->setRecordsPerPage($per_page);
}
$pagination_interval = array(12=>'12',25=>'25',50=>'50',100=>'100',0=>'ALL');
$grid->setPaginationInterval($pagination_interval);

I would think that the grid should automatically recognize that all records are being asked for and ignore the start value. Or is there some way to suppress the start value so it isn't passed in the get values of the URL when selecting a pagination interval value of zero? I have gone through the documentation, but have not found a way to override the start value parameter.

danhammari commented 10 years ago

Here is the workaround I am using in the zend controller's init() method to suppress the division by zero error that occurs when "perPage" is set to zero and "start" is specified:

        // mitigate zfdatagrid perPage/start conflict
        if( $this->getRequest()->getParam( 'perPage', false ) === '0' ){
            if( $this->getRequest()->getParam( 'start', false ) !== false ){
                $this->getRequest()->setParam( 'start', 0 );
            }
        }
danhammari commented 10 years ago

Here is the warning I get when perPage is set to zero and start is not zero:

Warning: Division by zero in \Bvb\Grid\Deploy\Table.php on line 1358

I am using Bvb_Grid version 0.8