Search code examples
gridviewyii2yii2-extension

Yii2, DynaGrid, GridView: Setting the column width


I try to set column width in DynaGrid:

echo DynaGrid::widget([
    'columns' => [
         [
            'attribute' => 'shortcut',
            'width' => '75px',
        ],
        ...
    ],
    ...
]);

See: http://demos.krajee.com/dynagrid

It does not work. In the resulting table is the th element set correctly:

<th style="width:75px;" data-col-seq="0">...</th>

But in the colgroup is for the same column another value:

<colgroup>
    <col style="width: 32px;">
    ...

How can I change the width values in the colgroup?


Solution

  • In the end I have found one elegant solution, which works. The minimum width of the search fields in the head of the DynaGrid table is set in assets/dynagrid/index.css:

    .form-control {
        min-width: 55px;
    }
    

    Pretty simple :-)

    It solves the issue, which was reported by users. They could not see the input in the search field, if the column was too narrow.