[英]Yii CGridView add class or style for header cell
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或样式?
Use headerHtmlOptions
. 使用
headerHtmlOptions
。
'columns'=>array(
array(
'name'=>'id',
'header'=>'#',
'htmlOptions'=>array('style'=>'width: 50px; text-align: center;', 'class'=>'zzz'),
'headerHtmlOptions'=>array(...),
),
filterHtmlOptions filterHtmlOptions
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',
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.