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.
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.
yon can also use the tooltip/title
with filterOptions
[
'attribute' => 'name',
'label' => 'labelname',
...
....
'filterOptions' => [ 'title' => 'prova'],
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With