msoa
July 11, 2013, 3:25pm
1
Hello friends,
I want set an id for td and obtain something like this:
[html]
<td id="3" >name</td>
[/html]
but with this setting:
$this->widget('zii.widgets.grid.CGridView',array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'title',
array(
'name'=>'create_date',
'value'=>'Yii::app()->jdate->date("d M y",(int) strtotime($data->create_date))',
'htmlOptions'=>array('id' => '$data->id'),
),
I get this:
[html]
<td id="$data->id" >name</td>
[/html]
Why $data->id evaluated as string?
jayant
(Codesutras)
July 11, 2013, 4:39pm
2
msoa:
Hello friends,
I want set an id for td and obtain something like this:
[html]
<td id="3" >name</td>
[/html]
but with this setting:
$this->widget('zii.widgets.grid.CGridView',array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'title',
array(
'name'=>'create_date',
'value'=>'Yii::app()->jdate->date("d M y",(int) strtotime($data->create_date))',
'htmlOptions'=>array('id' => '$data->id'),
),
I get this:
[html]
<td id="$data->id" >name</td>
[/html]
Why $data->id evaluated as string?
Try something like give on this link
Keith
(Kburton)
July 11, 2013, 5:25pm
3
If you don’t want to extend the framework classes, you could just wrap your content in a div and apply the ID to that instead of the table cell itself.
array(
'name'=>'create_date',
'type'=>'html',
'value'=>function($data){
return CHtml::tag('div', array('id'=>$data->id),
Yii::app()->jdate->date("d M y",(int) strtotime($data->create_date)));
}
),
msoa
July 11, 2013, 6:01pm
4
So, what is the htmlOptions usage in CGridColumn ?
jayant
(Codesutras)
July 11, 2013, 6:05pm
5
its a different one. htmlOptions is a property for CGridView where you can define html options for CgridView.
SO, if you want to set a id for CgridView then you can easily do it by ‘id’=>‘test’
But as per your code you was trying to add dynamic id for column for cgridview.Which will be done by as i have suggested in my previous comment.
in your code you are setting htmlOption for column for CGridView.
So, this is a difference here.
msoa
July 11, 2013, 8:26pm
6
its a different one. htmlOptions is a property for CGridView where you can define html options for CgridView.
SO, if you want to set a id for CgridView then you can easily do it by ‘id’=>‘test’
But as per your code you was trying to add dynamic id for column for cgridview.Which will be done by as i have suggested in my previous comment.
in your code you are setting htmlOption for column for CGridView.
So, this is a difference here.
But in api is:
CDataColumn is extended from [color="#FF0000 "]CGridView [/color]CGridColumn hence CDataColumn have an property named $htmlOptions.
Keith
(Kburton)
July 11, 2013, 9:42pm
7
The htmlOptions attribute doesn’t take a callback function, so you can’t generate different values for each row. It’s used for static configuration that applies to every row.
msoa
July 12, 2013, 1:06am
8
Dear friend, can you take an example of htmlOptions usage in CDataColumn , please?
jayant
(Codesutras)
July 12, 2013, 4:47am
9
Yes i do agree with you and yes you can set htmlOptions also for CDataColumn.And there is nothing wrong with it.
Suppose you are adding class attribute
'htmlOptions'=>array('class' => 'testing'),
and it will work.
But the thing is that you have to add dynamic value in id attribute field. Which is going to be pass in array. So, there is a issue for parsing a variable.
That’s why i have suggested to overwrite this class.So easily you can set it dynamic.