Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.1.5

Request #8341 Passing column meta data to formatter
Submitted: 2006-08-01 20:11 UTC
From: michael at apison dot com Assigned: olivierg
Status: Closed Package: Structures_DataGrid_Renderer_Smarty (version 0.7.1)
PHP Version: 5.1.4 OS: irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2006-08-01 20:11 UTC] michael at apison dot com (Michael Caplan)
Description: ------------ Hi there, I'm need a decent way to define the width of a colum set when rendering the datagrid as a table (I'm using the Smarty renderer, but this is a problem probablly applicable across different renderers). If I know in the template in advance how many columns and each desired width, then I can code some logic in the template (although that tends to be a bit messy). However, in my case, the columns are variable, and ideally should be set outside of the design logic. I raised this issue on the PEAR general list which resulted in Mark suggesting that either I extend the appropriate classes, or write a feature request. Well, I think this is a good idea that probably is applicable to a range of cases, so I'm thinking that such a solution should make its way into the package proper. What I'd like to be able to do is something like this: $datagrid->addColumn( new Structures_DataGrid_Column( 'ID', 'id', 'id', array('width' => '5%'), ) ); $datagrid->addColumn( new Structures_DataGrid_Column( 'Title', 'title', 'title', array('width' => '50%'), ) ); etc... I looked into the logistics of carrying over column attributes to the built Header vars that are assigned to Smarty. This would require a change to Structures_DataGrid_Renderer::build(). At line 665, something like this could be added: $attribs = $column->attribs; $this->_columns[$index] = compact('field','label', 'attribs'); Now in the Smarty renderer we can access this data. If buildHeader() was modified as such: $prepared[$index]['attribs'] = $spec['attribs']; $prepared[$index]['label'] = $spec['label']; (line 223) This data is now availble for template access. Waddya think? Michael

Comments

 [2006-08-03 21:47 UTC] olivierg at php dot net (Olivier Guilyardi)
The attributes where indeed not carried by the Smarty Renderer from the Column object to the Smarty template. You seem to have pretty well understood the "logistics" involved. Actually, I've added support for the "columnAttributes" to the Smarty driver, in a similar way to the HTMLTable driver. It's in the CVS. There's no reason to put this information into the main $_columns property, especially because this property is meant to contain non-driver-specific informations, while attributes are only relevant for XML/HTML formats. The attributes are converted to a string before they're passed to Smarty. It's a little intrusive, but I think it's much more handy. You might use the attributes in your templates with a simple thing like: <td {$columnSet[col].attributes}> ... </td> This bug is closed. Thanks for your report.