我尝试了以下方法(请参阅Ulises Trujillos Aguirre 的建议):
!重要修饰符
'columns' => [
[
'attribute' => 'shortcut',
'width' => '75px !important',
],
CSS
'columns' => [
[
'attribute' => 'shortcut',
'width' => '75px !important',
'options' => [
'class' => 'col-width-75',
],
],
在 assets/dynagrid/index.css 中:
.col-width-75 {
width: 75px !important;
}
jQuery
在 assets/dynagrid/index.js 中:
$(document).ready(function () {
$('.col-width-75').css('width:75px !important');
...
});
我收到以下输出:
<th style="width:75px !important;" data-col-seq="0">...</th>
...
<col class="col-width-75" style="width: 32px;">
在开发者工具中:
对于th:
element.style { 宽度: 150px !important; }
对于col:
element.style {
宽度:43px;
}
.col-width-150 { 宽度:150px !重要;}
它看起来不错,但在浏览器中有 32px 的列宽。所以看起来,唯一可行的解决方案是不正确的解决方案,我想避免:
[
'attribute' => 'shortcut',
'label' => 'S ',
'encodeLabel' => false,
],