Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter Placeholders with Yii2 [closed]

Tags:

php

gridview

yii2

Does anyone know how to implement a placeholder or tooltip on the Gridview filter of the Yii2 Framework? I need something that stands out to the user to let them know that textbox is in fact a search filter.

Look forward to hearing responses.

Preview

like image 276
Winkmei5ter Avatar asked Jun 25 '15 11:06

Winkmei5ter


2 Answers

Placeholder could be realized with this:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel'  => $searchModel,
    'columns'      => [
        [
            'attribute' => 'name',
            'filterInputOptions' => [
                'class'       => 'form-control',
                'placeholder' => 'Type in some characters...'
             ]
        ],
        ['class' => 'yii\grid\ActionColumn' ],
    ],
]); ?>

class should be provided, though it is not a must - it is just the default styling class.

Setting this globally

The only way that I found is in config/web.php that is used for the application configuration:

$config = [
    ...
    'on beforeRequest'          => function ($event) {
        Yii::$container->set('yii\grid\DataColumn', [
            'filterInputOptions' => [
                'class'       => 'form-control',
                'placeholder' => 'Type in some characters...'
            ]
        ]);
    },
    ...
];

This is an event handler. On each request DataColumn will be configured to use the placeholder. Some detail information can be found here. Now you don't need to adjust any GridView configuration in order to have the placeholder. In the handler you can change other configurations as well, of course.

like image 88
robsch Avatar answered Nov 11 '22 15:11

robsch


yon can also use the tooltip/title with filterOptions

 [
            'attribute' => 'name',
            'label' => 'labelname',
            ...
            ....
            'filterOptions' => [ 'title' => 'prova'],
        ],
like image 22
ScaisEdge Avatar answered Nov 11 '22 14:11

ScaisEdge