php - 在复选框列 Yii2 Gridview 小部件上添加过滤器
问题描述
您能帮我在网格视图小部件 yii2 上的复选框列上添加过滤器吗?我使用 yii\grid\CheckboxColumn 在我的 index.php 的 Gridview 中添加复选框列。但我无法在列上方添加过滤器作为其他列。请在下面查看我的代码。
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
['label' => 'Client', 'attribute' => 'name', 'value' => 'client.view', 'format' => 'raw'],
'postCode',
'start',
'end',
[
'attribute' => 'categoryID',
'value' => 'category.name',
'filter' => ArrayHelper::map(Servicecategory::find()->where(['status' => true])->asArray()->all(), 'id', 'name')
],
[
'attribute' => 'status',
'headerOptions' => ['style' => 'width:12%'],
'value' => 'Status',
'filter' => array_filter(\app\models\Booking::$statuses),
'filterInputOptions' => ['class' => 'form-control', 'prompt' => 'All']
],
['class' => 'yii\grid\CheckboxColumn',
'header' => 'follow Up',
'contentOptions' => ['class' => 'text-center'],
'checkboxOptions' => function($model, $key, $index) {
$url = \yii\helpers\Url::to(['booking/followup/' . $model->id]);
return ['onclick' => 'js:followUp("' . $url . '")', 'checked' => $model->followUpEmailSent ? true : false, 'value' => $model->followUpEmailSent];
}
],
['class' => 'yii\grid\ActionColumn',
'headerOptions' => ['style' => 'width:10%'],
'template' => '{view} {approval} {update} {delete} ',
'buttons' => [
/* 'view' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', ['/booking/review/' . $model->id], [
'title' => Yii::t('app', 'Review'),
]);
}, */
'approval' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-ok"></span>', ['/booking/approval/' . $model->id], [
'title' => Yii::t('app', 'Additional Details'),
'class' => 'error',
]);
}
],
],
],
]);
以下是复选框列。
['class' => 'yii\grid\CheckboxColumn',
'header' => 'follow Up',
'contentOptions' => ['class' => 'text-center'],
'checkboxOptions' => function($model, $key, $index) {
$url = \yii\helpers\Url::to(['booking/followup/' . $model->id]);
return ['onclick' => 'js:followUp("' . $url . '")', 'checked' => $model->followUpEmailSent ? true : false, 'value' => $model->followUpEmailSent];
}
],
有人可以帮忙吗?
解决方案
你可以使用你的 Gii 工具-> CRUD 生成器来创建你的过滤器文件。然后你可以像这样将你的参数传递给搜索模型:
$searchModel = 新搜索模型;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
您需要从 SearchModel 返回您的 $dataProvider
推荐阅读
- apache - 如何禁止使用 apache 请求特定目录的 IP 地址
- javascript - 上传图片后在本机中获取downloadURL
- python - Python如何避免“副作用”
- apache - 错误:Apache 意外关闭。[阿帕奇,xampp,phpmyadmin]
- javascript - 查询用户输入 - API
- macos - 在 Xamarin Forms 应用程序中构建路径 iOS v MacOs 的问题
- sql - Rails 更新后查询中断。Arel::Visitors::UnsupportedVisitError。改为构造一个 Arel 节点
- mysql - 使用 mysql 为每个产品保留的总购买、销售和库存
- scala - java.io.EOFException 不是空文件上的 SequenceFile
- javascript - 如何更改 react-responsive-carousel 的 transform:translateX?