Saturday, June 1, 2013

How to Change CgridView table class? - Yii Framework

I can see in the source code of my page that CgridView has
<table class="items">
 
and I want to change this to
<table class="example">
 
It can be done by defining the 'itemsCssClass' key as widget's configuration.

So:

$this->widget('zii.widgets.grid.CGridView', array(
'itemsCssClass' => 'table-class',
'htmlOptions' => array('class' => 'example'))



gives me:

<div class="example"><table class="table-class"></table></div> 
 
Complete example of using CGridView: 

<?php 
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    "itemsCssClass" => "table_design_1",
    "htmlOptions" => array(
        "class" => "div_design_1"
    ),
    'columns'=>array(
        array(
            'name'=>'family_name', 
            'header'=>'First name',
            'type' => 'raw',
            'value' => 'CHtml::link($data->family_name,$data->id)'
        ),
        array(
            'name'=>'given_name', 
            'header'=>'Last name',
            'type' => 'raw',
            'value' => 'CHtml::link($data->given_name,$data->id)'
        ),
        array(
            'class'=>'CButtonColumn',
            'viewButtonUrl'=>'Yii::app()->request->getBaseUrl(true)."/contact/view/".$data["id"]',
            'updateButtonUrl'=>'Yii::app()->controller->createUrl("update",$data->primaryKey)',
            'deleteButtonUrl'=>'Yii::app()->controller->createUrl("delete",$data->primaryKey)',
            "htmlOptions" => array(
                'style'=>'width: 60px;'
            )
        )
    )
)); ?>

1 comment: