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

Request #3188 Can the callbacks pass the DataGrid_Column?
Submitted: 2005-01-13 15:34 UTC
From: dasher at inspiredthinking dot co dot uk Assigned: asnagy
Status: Closed Package: Structures_DataGrid
PHP Version: Irrelevant OS: N/A
Roadmaps: (Not assigned)    
Subscription  


 [2005-01-13 15:34 UTC] dasher at inspiredthinking dot co dot uk
Description: ------------ Can the callback code pass a DataGrid_Column as one of the arguments? Sometimes the width of the cell depends on what the callback does. In the project I'm working on - links are generated - which depend on the arguments being passed in. Reproduce code: --------------- My column is: $dg->addColumn(new Structures_DataGrid_Column('Actions', null, null, array('width' => '30%', 'align'=>'center'), null, "recordLinks(\$field=auth_user_id,\$type=edit|del)")); With my callback recordLinks function: function recordLinks($params) { $script = ScriptName(); $editTypes = explode("|",$params['type']); reset($editTypes); $actions = ""; while(list($key, $type) = each($editTypes)) { if (!(strpos($type,":")===false)) { $elements = explode(":",$type); $opTag = $elements[0]; $url = $elements[1]; } else { $url = $script; $opTag = $type; } $actions .="<a href='{$url}?op={$opTag}&id={$params['record'][$params['field']]} '>".ucfirst($opTag)."</a> | "; } $actions = substr($actions,0,strlen($actions)-2); return $actions; }

Comments

 [2005-01-18 19:29 UTC] asnagy at webitecture dot org
I don't think this is necessary. You are asking for data to be passed into the formatter callback that is speccified in the same line of code. If you want the cell width, why don't you pass that into the callback also?
 [2005-01-19 10:26 UTC] dasher at inspiredthinking dot co dot uk
I'd like to be able to set the cell width. The callback generates some data - which affects the size of the cell. If the cell size has been specified when at addColumn - the callback might want to adjust things.
 [2005-01-19 20:17 UTC] asnagy at webitecture dot org
That sounds a bit tricky. What if you have one cell trying to make the width = 200px and another cell trying to make the width = 100px. Since they are all in the same column, you will not get the results that you desire. I think that this request is outside the scope of the formatter function. It's goals are to format what is inside the cell and not the cell itself. I think the next step for this feature is to look into a new column class dedicated to controlling the size similiar to Bug#3170.
 [2005-02-01 19:04 UTC] rolf at winmutt dot com
I think formatter should be modified to accpet complex data types as I mentioned in bug 3089 (which I had completelty labeled incorrectly). The patch I supplied would allow any complex data to be passed, not just some fixed string as we are currently limited to. In php5 atleast you can pass any type of complex data into call_user_func. This patch : snowcrash DataGrid # diff Column.php ~winmutt/pear/Structures_DataGrid/DataGrid/Column.php 186,189c186 < } elseif (is_array($this->formatter) && is_array($this->formatter[0])) { < $formatter = $this->formatter[0]; < $paramList = array_merge($this->formatter[1], $record); < } else { --- > } else { 196c193 < $result = call_user_func($formatter, ($paramList?$paramList:$record)); --- > $result = call_user_func($formatter, $paramList); works just fine when passing complex data in : $dg->addColumn(new Structures_DataGrid_Column($v, $v, $v, null, null, array(array(&$this,'printCrossLink'),array($v))));
 [2005-05-16 20:15 UTC] asnagy
Passing the column object itself into the column formatter is unnecessary.