PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Structures » Structures_DataGrid » Bug #5758

Extra parameters for Structures_DataGrid_Column::formatter() callback

Details

Request #5758Extra parameters for Structures_DataGrid_Column::formatter() callback
Submitted2005-10-23 13:35 UTC
Fromnick at foobar dot org
Assignedwiesemann
StatusClosed
PackageStructures_DataGrid
PHP Version4.4.0
Roadmaps(Not assigned)

Comments

[2005-10-23 13:35 UTC] nick at foobar dot org

Description:
------------
Structures_DataGrid 0.62.

If the formatter() option is used in the addColumn() function, the only parameters passed to the formatter callback are the row $record and also any parameters specified in the callback definition. This means that unless you explicitly pass back the column name in the callback definition, the callback has no way of figuring out what column is being formatted. It would be very handy to pass the column field name into the Structures_DataGrid_Column::formatter() so that this information could be passed to the callback automatically.

Taking an example, at the moment, the argument passed to formatter() looks like this:

array (
'record' => array (
'colname1' => 'colvalue1,
'colname2' => 'colvalue2,
[etc]
),
'arg1' => 'argvalue1', // user defined
'arg2' => 'argvalue2', // user defined
);

What would be handy is something like the following:

array (
'record' => array (
'colname1' => 'colvalue1,
'colname2' => 'colvalue2,
[etc]
),
'fieldName' => 'colname4',
'columnName' => 'Blah Column',
'orderBy' => 'colname3',
'attribs' => null,
'arg1' => 'argvalue1', // user defined
'arg2' => 'argvalue2', // user defined
);

This can be implemented by the patch below.

Doing this would allow much greater flexibility in the formatter callback, because you could then automatically figure out which column you were working on and what attributes were being applied to it and so forth.

Test script:
---------------
--- Structures/DataGrid/Column.php.orig Sun Oct 23 13:51:59 2005
+++ Structures/DataGrid/Column.php Sun Oct 23 13:53:48 2005
@@ -174,6 +174,10 @@
// Process the parameters
$paramList = array();
$paramList['record'] = $record; // Auto pass the record array in
+ $paramList['fieldName'] = $this->fieldName; // Auto pass the field name
+ $paramList['columnName'] = $this->columnName; // Auto pass the field name
+ $paramList['orderBy'] = $this->orderBy; // Auto pass the field name
+ $paramList['attribs'] = $this->attribs; // Auto pass the field name
foreach($parameters as $param) {
$param = str_replace('$', '', $param);
if (strpos($param, '=') != false) {