Changing the width of a filter column in CGridview

  • Yii Articles

  • Blog Subjects

  • I recently spent an hour or so trying to reduce the width of columns in a CGridView. As I was trying to squash the grid into a narrow space, I wanted some columns to be narrower than others.

    I tried setting the headerHtmlOptions and the HtmlOptions and I could see these coming through in the HTML but found that it was the width of the input boxes in the filter row that was throwing out width of the column.

    I finally found a solution that works (for me). I know this is a bit of a hack but it works!

    I ended up using attribute names in CSS to determine the max-width of the input boxes as follows:

     PHP |  copy code |? 
    1
    input[name="Properties[ref]"]
    2
    {
    3
        max-width: 55px;
    4
    }

    It doesn’t seem quite the right way to do it, but it works. I would be interested if anyone has found a better way …

    Setting the width of columns in a CGridView