rymonator
(Ryan Bobrowski)
September 1, 2011, 1:42pm
1
Hello, I have a CGridView with a CLinkColumn:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'meetings-grid',
'dataProvider'=>$meetings->search(),
'filter'=>$meetings,
'columns'=>array(
array( 'class'=>'CLinkColumn', //here is the link column
'header'=>'Meeting Name',
'labelExpression'=>'$data->name',
'urlExpression'=>'Yii::app()->createUrl("/meetings/view", array("id"=>$data["id"]))',
),
'days',
'time',
'recurrence',
array(
'class'=>'CButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("/meetings/view", array("id"=>$data["id"]))',
'updateButtonUrl'=>'Yii::app()->createUrl("/meetings/update",array("id"=>$data["id"]))',
'deleteButtonUrl'=>'Yii::app()->createUrl("/meetings/delete", array("id"=>$data["id"]))'
),
),
));
That works great and everything, but the search filter input box that appears over the attributes days, time, and recurrence does not appear over the CLinkColumn for $data->name. What is the process to add a filter box for CLinkColumns? Thanks.
mbi
(mbi)
September 1, 2011, 4:33pm
2
have a look at CLinkColumnm, CDataColumn, CGridColumn
CLinkColumn extends CGridColumn which prints a blank cell
you have to extend CLinkColumn the way CDataColumn does
klah
(Klah)
May 2, 2012, 8:30am
3
I have the same issue.
"have a look at CLinkColumnm, CDataColumn, CGridColumn
CLinkColumn extends CGridColumn which prints a blank cell
you have to extend CLinkColumn the way CDataColumn does"
rymonator - did you manage to write a class for this?
klah
(Klah)
May 2, 2012, 9:13am
4
I have the same issue.
"have a look at CLinkColumnm, CDataColumn, CGridColumn
CLinkColumn extends CGridColumn which prints a blank cell
you have to extend CLinkColumn the way CDataColumn does"
rymonator - did you manage to write a class for this?
This might do the trick:
class FMSearchableLinkColumn extends CLinkColumn {
public $name;
public $filter;
/**
* Renders the filter cell content while enabling searching in a link column
*
* @return void
*/
protected function renderFilterCellContent() {
if (is_string($this->filter)) {
echo $this->filter;
} else if ($this->filter !== false && $this->grid->filter !== null && $this->name !== null && strpos($this->name, '.') === false) {
if(is_array($this->filter)) {
echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, array('id' => false, 'prompt' => ''));
} else if($this->filter === null) {
echo CHtml::activeTextField($this->grid->filter, $this->name, array('id' => false));
}
}
}
}
When using this class instead I should be able to show my column as a link, while still being able to search in that column.
To do this, your column should look something like this:
array(
'class' => 'FMSearchableLinkColumn',
'name' => '[the column name here]',
'filter' => null,
'header' => '[some header]',
'labelExpression' => '[some label here]',
'urlExpression' => '[your url here]'
),
any thoughts ppl?
klah
(Klah)
May 2, 2012, 10:17am
5
Sniper came up with a much simpler and pretty solution:
http://www.yiiframework.com/forum/index.php/topic/7175-clinkcolumn-and-sorting/
array(
'name' => 'field_name',
'type' => 'raw',
'value' => 'CHtml::link($data->field_name,$data->field_name)'
),