可以通过以下方式实现占位符:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'name',
'filterInputOptions' => [
'class' => 'form-control',
'placeholder' => 'Type in some characters...'
]
],
['class' => 'yii\grid\ActionColumn' ],
],
]); ?>
虽然不是必须的,但应该提供class
,这只是默认样式类。
全局设置
我找到的唯一方法是在用于应用程序配置的config/web.php文件中:
$config = [
...
'on beforeRequest' => function ($event) {
Yii::$container->set('yii\grid\DataColumn', [
'filterInputOptions' => [
'class' => 'form-control',
'placeholder' => 'Type in some characters...'
]
]);
},
...
];
这是一个事件处理程序。在每个请求中,DataColumn将被配置为使用占位符。可以在此处找到一些详细信息。现在您无需调整任何GridView配置即可使用占位符。当然,在处理程序中您也可以更改其他配置。
filterOptions
中使用 tooltip/title
。 [
'attribute' => 'name',
'label' => 'labelname',
...
....
'filterOptions' => [ 'title' => 'prova'],
],