Re: Structure_Datagrid - paging past last page?
| From: | Andrew Nagy | Date: | Mon, 07 Mar 2005 14:44:49 +0000 |
| Subject: | Re: Structure_Datagrid - paging past last page? | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-17907@lists.php.net to get a copy of this message | ||
Matte, thanks for the work. Can you send a diff against the code in CVS so we can see exactly what you changed?
Thanks!
Andrew
Matte Edens wrote:
So I did a little poking around and came up with this, which works perfectly, IMHO. It should be datasource agnostic as well. Array, DataObject, and DB support the count() function and all other datasources extend Array. I've only used the Array datasource though. Replace the "fetchDataSource()" function in PEAR\Structures\DataGrid\Renderer.php with this code... function fetchDataSource() { if ($this->_dataSource != null) {$recordCount = $this->_dataSource->count(); $page = (($this->rowLimit*($this->page-1)) > $recordCount) ? floor($recordCount / $this->rowLimit) : $this->page-1; $recordSet = $this->_dataSource->fetch( (($page)*$this->rowLimit), $this->rowLimit, $this->sortArray[0], $this->sortArray[1]); if (PEAR::isError($recordSet)) { return $recordSet; } else { $this->recordSet = $recordSet; if (count($columnSet = $this->_dataSource->getColumns())) { $this->columnSet = $columnSet; } }} } This does one of two things based on your perPage setting and what page you are requesting. 1) if your dataset is larger than your perPage setting and you are requesting a page past the total number of pages, it will show you the last page of data 2) if your dataset is smaller than your perPage setting, it will show you all records. you only have 50 pages? asking for page 100, or 1000, or infinity - 1? it doesn't matter. you'll see the last page of data. I compared this against the latest revision of Renderer.php in CVS (1.20) and it's a clean replacement. If you deem it worthy. <grin> I believe this is the appropriate location for this logic. -- matte - matte@arubanetworks.com Matte Edens wrote:I've been looking but I can't find a facility for Structure_Datagrid (SDG) to force the display of the last page of data if you are requesting a page greater than the total number of pages. If I have a dataset of 12 records, and my perPage setting is 5, then I have 3 pages. If I go to the second page, then set my perPage to 15 records, I get empty output. Since I'm asking for 15 records per page, all my records will be on page 1 but SDG thinks I still want to see page 2. Is this something that I should be pre-empting before I tell SDG what page it should show? Is it something that can be implemented in SDG? IMHO, SDG should know if I'm going past the last page and display the last set of data (whether it's a full dataset or not).