Re: DataGrid_Column

From: Date: Sat, 30 Sep 2006 04:24:20 +0000
Subject: Re: DataGrid_Column
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-25307@lists.php.net to get a copy of this message
On 9/29/06, Justin Patrin <papercrane@gmail.com> wrote:
On 9/29/06, Chris Boget <chris.boget@wild.net> wrote: I'm trying to get the value of one of the columns in my table passed to nl2br for display. However, when the column value does get displayed, it shows up as Array. Here is how I'm adding my column to the datagrid: $datagrid = new Structures_DataGrid( 10 ) $datagrid->bind( $users ); $datagrid->addColumn(new Structures_DataGrid_Column('User', 'uid', 'uid')); $datagrid->addColumn(new Structures_DataGrid_Column('Comments', 'comments', 'comments', null, null, 'nl2br()')); echo $datagrid->render( DATAGRID_RENDER_TABLE ); When it gets displayed, it shows the user column fine but the comments column has 'Array'. In Structures_DataGrid_Column, the formatter() method is running the call_user_func() on line 236 but I'm not sure if that's the one it should be using. Am I doing this wrong? Can I not use nl2br()? 'nl2br', not 'nl2br()'
Oops, that's wrong too. I forgot how the formatters work for a minute. :-P You have to write your own function as the formatter gets an array with multiple options in it, one of which is 'record' which is an associative array of the entire record. You want something like this: function formatComment($options, $extra) { return nl2br($options['record']['comment']); } $datagrid->addColumn(new Structures_DataGrid_Column('Comments', 'comments', 'comments', null, null, 'formatComment')); -- Justin Patrin

« previous php.pear.general (#25307) next »