yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.9k forks source link

Auto calculated width in GridView columns doesn't take care of placeholder text in search columns #20244

Closed fiSCIENCES closed 3 months ago

fiSCIENCES commented 3 months ago

Hello,

It's my first report, so excuse me if not done in the perfect manner.

Here my code:

['attribute' => 'category',
. 'filter' =>  Html::activeDropDownList($searchModel, 'language', array_combine(Yii::$app->languageSelector->supportedLanguages,Yii::$app->languageSelector->supportedLanguages),['class'=>'form-control','prompt' => Yii::t('SLc', 'str_categories_filter_all')])
]

So I add a placeholder text, but it is larger than the rest. So I need to specify the width with this code:

'headerOptions' => ['style' => 'width:95px']

But it could be an issue with different devices, screen size...

Would be great if it could include placeholder text width in auto width calculation.

Thank you.

bizley commented 3 months ago

This is out of the scope of the GridView - you have to take care of it by yourself by using css / javascript - everything you need is already available with headerOptions like you mentioned.

fiSCIENCES commented 3 months ago

Hi @bizley,

If you set up a header, a text field or a drop-down list (etc.), GridView use them top calculate the auto width minimum. But if you set up a placeholder, it does not! I disagree with you. Should be consistent.

Thank you.

bizley commented 3 months ago

Hm, I'm confused, is GridView adding any code to set this auto width minimum?

fiSCIENCES commented 3 months ago

No, I use this minimum to prevent GridView column width from being calculated under the width of the placeholder. Because GridView DataColumn auto calculated the width of each column, but forgot to check with the placeholder.

bizley commented 3 months ago

Please explain this "Because GridView DataColumn auto calculated the width of each column".

fiSCIENCES commented 3 months ago

Sorry, my English seem not enough.

When you create a GridView, you don't specify column width. DataColum will set them base on string length for each column. So when you use another screen size, column width are automatically recalculated from space available.

Thank you.

rob006 commented 3 months ago

AFAIK GridView does not specify columns width in any way. It just generates <table> and it is browser responsibility to render it in most optimal way. If you think that it is not optimal, you can either report it as bug in browser, or create an extension that would calculate widths using JS and overwrite browser behavior.

fiSCIENCES commented 3 months ago

OK, so there is definitely something I'm missing in the base core here. I will look further at it.

Thank you.