我正在尝试在网格视图标题中添加名为按月排序的自定义过滤器,这是我正在修改的网站上一版本的示例,请参见下图
我正在查看网格视图的layout
选项,并在{items}
GridView::widget(
[
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'layout' => '{summary}{errors}' . \kartik\widgets\Select2::widget(
[
'model' => $searchModel,
'attribute' => 'filter_month',
'theme' => \kartik\widgets\Select2::THEME_DEFAULT,
'data' => $searchModel->getFilterMonths(),
'pluginEvents' => [
"select2:select" => 'function() { $("#w2").submit();}',
// 'select2:select'=> new \yii\web\JsExpression("function(){console.log('here')}"),
],
'options' => [
'placeholder' => '--Select Month--',
],
'pluginOptions' => [
'allowClear' => true,
'width' => '160px',
],
]
) . '{items}{pager}',
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'name',
'title',
'catalog',
'upc_code',
[
'attribute' => 'created_on',
'label' => 'Created On',
'filter' => \yii\jui\DatePicker::widget(['dateFormat' => 'yyyy-MM-dd', 'model' => $searchModel, 'attribute' => 'created_on']),
'format' => 'html',
],
[
'attribute' => 'status',
'label' => 'Status',
'format' => 'raw',
'value' => function ($data) {
switch ($data->status) {
case 0:
return "Being Edited (" . $data->created_on . ")";
break;
case 1:
return ($data->maxdate == '') ? 'Active' : 'Active';
break;
case 2:
return "Expired";
break;
}
},
],
['class' => 'yii\grid\ActionColumn'],
],
]
);
现在我想在从下拉列表中选择一个选项时提交过滤器表单,但无法弄清楚如何使用下拉选项附加默认过滤器提交事件,以便在我选择时过滤结果下拉列表中的任何选项。
答案 0 :(得分:3)
对于自定义过滤器,您使用了完美的布局,但必须将自定义字段作为自定义选择器提供。
"filterSelector" => "#". Html::getInputId($searchModel, 'AttributeName'),"