php Yii CGridView 为标题单元格添加类或样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14604333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:37:23  来源:igfitidea点击:

Yii CGridView add class or style for header cell

phpyii

提问by dr0zd

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

我想为特定列中的标题单元格设置一些样式或 css 类。

This changes css only for data cells in a column.

这仅更改列中数据单元格的 css。

        '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?

如何在此列的标题单元格中设置 css 或样式?

回答by topher

Use headerHtmlOptions.

使用headerHtmlOptions.

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

回答by Gerhard Liebenberg

filterHtmlOptions

过滤器HTML选项

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

如果您想设置用户在过滤器框中输入的内容的样式 - 例如“text-align : right” - 那么

'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) 的样式,而不是内部过滤器容器 (div) 或输入元素:

<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',
    });
});