I want to fix the width of the columns generated using CGRIDVIEW. One way to do this is by adding a <div>
tag after every <td>
such that I can assign styling to that div.
The Structure I am looking for is as such ==>
<td><div style='width:50px;'>$data['name']</div></td>
When I write this into the firebug .. I get the output as required... but now I need to code it....
View which holds GridView is ==>
$this->widget('bootstrap.widgets.TbGridView', array(
'type' => 'bordered striped',
'id' => 'bike_search',
'dataProvider' => $model->search_bikes(),
'ajaxUpdate' => true, //false if you want to reload aentire page (useful if sorting has an effect to other widgets)
'filter' => null,
'template'=>'<div style="overflow:auto;">{items}</div>{pager}{summary}',
'columns' => $selected_columns,
'enablePagination' => true
));
The Model is ==>
$selected_columns[] = array(
'header' => 'Name',
'name' => 'name',
'value'=>'$data["name"]',
);
How do I solve it ?
if you have array data provider you can use $data["name"]
otherwise you have to use $data->name
!
array(
'header' => 'Name',
'name' => 'name',
'value'=> '"<div style=\"width:50px;\">" . $data["name"] . "</div>"',
//or
'value'=> function($data){
return '<div style="width:50px;">' . $data['name'] . '</div>';
}
)