This document is based on questions asked on PEAR general mailing list and other mailing lists and forums.
The setRequestPrefix() method is the solution for this problem. Each DataGrid for the page needs such a prefix that is internally used before the GET parameters for sorting and paging. An example of the usage:
require_once 'Structures/DataGrid.php'; $datagrid1 = new Structures_DataGrid(); $datagrid2 = new Structures_DataGrid(); $datagrid1->setRequestPrefix('trade_'); $datagrid2->setRequestPrefix('stock_'); $datagrid1->bind('SELECT * FROM trade', array('dsn' => DSN)); $datagrid2->bind('SELECT * FROM stock', array('dsn' => DSN)); $datagrid1->render(); $datagrid2->render(); |
Замечание: You need to call setRequestPrefix() before calling bind().
Currently there are four DataSource drivers that are recommended in the sense of efficiency:
DB_DataObject
DB_Table
DBQuery
MDB2
These four drivers will only fetch the needed records from the database. For example, if you have a row limit of 15 records per page, they will only fetch (up to) 15 records.
All other DataSource drivers can, of course, also be used. But there is no logic implemented (better said: implementable) to avoid fetching (or keeping in memory) unneeded records.
You need a formatter for the new column that should hold the row number. The first parameter that is passed to such a formatter function contains a currRow value with the row number per page. For calculating the row number relative to the whole table, you need to take also the getCurrentRecordNumberStart() method into account.
The following code snippet shows you how to define the formatter function and how to add the column (with # as the column label and right aligned values):
function formatRowNumber($params, $recordNumberStart) { return $params['currRow'] + $recordNumberStart; } $datagrid->addColumn( new Structures_DataGrid_Column( '#', null, null, array('style' => 'text-align: right;'), null, 'formatRowNumber', $datagrid->getCurrentRecordNumberStart() )); |
4. I'm using the Excel Renderer and would like to have the € sign in the resulting Excel file, but I always get only a box or some funny characters. How can I get the right € sign?
Instead of using an encoding like ISO-8859-15, you need to use Windows-1252.
Streaming support in Structures_DataGrid is intended to be used with large datasets. But it can also be used with very small datasets without loss of performance.
As always, there is an exception to this rule: When you're using one of the DataSource drivers that fetch data from a database and you have queries that need a lot of time for computation of the results, you should not use streaming, as running such a complex query multiple times will need even more time, of course.
Пред. | Начало | След. |
Introduction | Уровень выше | Installation |
HIVE: All information for read only. Please respect copyright! |