Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii CGridView add class or style for header cell

Tags:

php

yii

I want to set some style or css class for header cell in specific column.

This changes css only for data cells in a column.

        'columns'=>array(
            array(
                'name'=>'id',
                'header'=>'#',
                'htmlOptions'=>array('style'=>'width: 50px; text-align: center;', 'class'=>'zzz'),
            ),

How to set css or style in header cell of this column?

like image 959
dr0zd Avatar asked Jan 30 '13 12:01

dr0zd


2 Answers

Use headerHtmlOptions.

'columns'=>array(
        array(
            'name'=>'id',
            'header'=>'#',
            'htmlOptions'=>array('style'=>'width: 50px; text-align: center;', 'class'=>'zzz'),
            'headerHtmlOptions'=>array(...),
        ),
like image 101
topher Avatar answered Nov 07 '22 21:11

topher


filterHtmlOptions

If you want to style the content that the user enters in the filterbox - for example "text-align : right" - then

'filterHtmlOptions'=>array('style'=>'text-align: right'),

is not going to work, because it will only style the outer table cell (td), and not the inner filter-container (div) or input element:

<td style="text-align: right;">
    <div class="filter-container">
        <input>
    </div>
</td>

What you can do is add a class to the outer table cell:

'filterHtmlOptions'=>array('class'=>'filterBoxRight'),

which will result in this:

<td class="filterBoxRight">
    <div class="filter-container">
        <input>
    </div>
</td>

Then run the following code:

$(document).on('ready', function(){
    $('.filterBoxRight').find('.filter-container').find(':input').css({
        'text-align': 'right',
    });
});
like image 1
Gerhard Liebenberg Avatar answered Nov 07 '22 21:11

Gerhard Liebenberg