Yii2 框架 GridView 怎么设置搜索框不自动提交呀? [ 2.0 版本 ]
Yii2 框架 GridView 怎么设置搜索框不自动提交呀 鼠标失去焦点之后表单自动搜索了
视图代码
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use common\models\UserInfo;
use common\fnlib\Constants;
use dosamigos\datepicker\DatePicker;
use dosamigos\datepicker\DateRangePicker;
use common\models\OrderRecord;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\UserinfoSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = '用户筛选';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-info-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?php $get = Yii::$app->request->get(); array_unshift($get, 'export'); ?>
<p>
<?= Html::a('导出Excel', $get, ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'summary' => '第<b>{begin}-{end}</b>条',
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'user_phone_number',
[
'label' => '是否审核',
'attribute' => 'user_verify_type',
'format' => 'raw',
'filter' => ['' => '全部'] + UserInfo::$verifies,
'value' => function($data) {
$colors = [
UserInfo::USER_VERIFY_TYPE_NO => '',
UserInfo::USER_VERIFY_TYPE_PASS => 'green',
UserInfo::USER_VERIFY_TYPE_REFUSE => 'red',
UserInfo::USER_VERIFY_TYPE_SUBMITED => '#FFC125',
UserInfo::USER_VERIFY_TYPE_INTERNSHIP => 'purple',
UserInfo::USER_VERIFY_TYPE_NOLOGIN => 'gray',
];
if ($data->user_verify_type == UserInfo::USER_VERIFY_TYPE_SUBMITED) {
$checkAuthor = Html::a('去审核', ['userinfo/check', 'user_id' => $data->user_id]);
return '<span style="color:' . $colors[$data->user_verify_type] . '">' . UserInfo::$verifies[$data->user_verify_type] . ' ' . $checkAuthor . '</span>';
} else {
return '<span style="color:' . @$colors[$data->user_verify_type] . '">' . @UserInfo::$verifies[$data->user_verify_type] . '</span>';
}
},
],
[
'attribute' => 'deposit_status',
'filter' => UserInfo::$userDepositStatus,
'format' => 'raw',
'value' => function($data) {
$classMap = [
UserInfo::USER_DEPOSIT_STATUS_NO => 'text-muted',
UserInfo::USER_DEPOSIT_STATUS_YES => 'text-success',
UserInfo::USER_DEPOSIT_STATUS_ING => 'text-warning',
];
return '<span class="' . $classMap[$data->deposit_status] . '">' . UserInfo::$userDepositStatus[$data->deposit_status] . '</span>';
}
],
'id_card_city',
[
'label' => '芝麻信用',
'attribute' => 'zm_score',
'filter' => '<div class="input-group"><input type="text" class="form-control" name="UserinfoSearch[start_score]" value=""><span class="input-group-addon">to</span><input type="text" class="form-control" name="UserinfoSearch[end_score]" value=""></div>',
'format' => 'raw',
'value' => function($data) {
return $data->zm_score ? '<span class="text-danger">-</span>' : '<span class="text-success">'.$data->zm_score.'</span>';
},
],
[
'label' => '用车量',
'filter' => '<div class="input-group"><input type="text" class="form-control" name="UserinfoSearch[start_usecar_count]" value=""><span class="input-group-addon">to</span><input type="text" class="form-control" name="UserinfoSearch[end_usecar_count]" value=""></div>',
'format' => 'raw',
// 'value' => function($data) {
// return $data->usecar_count ? '<span class="text-danger">-</span>' : '<span class="text-success">'.$data->usecar_count.'</span>';
// },
],
[
'label' => '注册时间',
'attribute' => 'create_time',
'format' => 'raw',
'value' => function($data) {
return $data->create_time ? date("Y-m-d H:i:s", $data->create_time) : '-';
},
'filter'=>DateRangePicker::widget([
'name' => 'UserinfoSearch[start_create_time]',
'value'=> isset(Yii::$app->request->queryParams['UserinfoSearch'], Yii::$app->request->queryParams['UserinfoSearch']['start_create_time']) ? Yii::$app->request->queryParams['UserinfoSearch']['start_create_time'] : '',
'nameTo' => 'UserinfoSearch[end_create_time]',
'valueTo' => isset(Yii::$app->request->queryParams['UserinfoSearch'], Yii::$app->request->queryParams['UserinfoSearch']['end_create_time']) ? Yii::$app->request->queryParams['UserinfoSearch']['end_create_time'] : '',
'language' => 'zh-CN',
'size' => 'ms',
'clientOptions' => [
'autoclose' => true,
'format' => 'yyyy/m/dd',
'todayBtn' => true
]
]),
],
[
'label' => '审核时间',
'attribute' => 'driver_check_uptime',
'format' => 'raw',
'value' => function($data) {
return $data->create_time ? date("Y-m-d H:i:s", $data->create_time) : '-';
},
'filter'=>DateRangePicker::widget([
'name' => 'UserinfoSearch[start_check_time]',
'value'=> isset(Yii::$app->request->queryParams['UserinfoSearch'], Yii::$app->request->queryParams['UserinfoSearch']['start_check_time']) ? Yii::$app->request->queryParams['UserinfoSearch']['start_check_time'] : '',
'nameTo' => 'UserinfoSearch[end_create_time]',
'valueTo' => isset(Yii::$app->request->queryParams['UserinfoSearch'], Yii::$app->request->queryParams['UserinfoSearch']['end_check_time']) ? Yii::$app->request->queryParams['UserinfoSearch']['end_check_time'] : '',
'language' => 'zh-CN',
'size' => 'ms',
'clientOptions' => [
'autoclose' => true,
'format' => 'yyyy/m/dd',
'todayBtn' => true
]
]),
],
[
'attribute' => 'id_number',
'format' => 'raw',
'value' => function($data) {
return '不显示';
},
],
[
'attribute' => 'driver_card_number',
'format' => 'raw',
'value' => function($data) {
return '不显示';
},
],
'reg_city',
[
'attribute' => 'reg_from',
'format' => 'raw',
'value' => function($data) {
return $data->reg_from ? Html::a($data->reg_from, ['shopkeeper/view-by-code', 'code' => $data->reg_from]) : '-';
},
],
[
'label' => '是否被邀请',
'attribute' => 'invit_user_id',
'filter' => ['0'=>'否', '1'=>'是'],
'format' => 'raw',
'value' => function($data) {
return $data->invit_user_id ? '<span class="text-danger">是</span>' : '<span class="text-success">否</span>';
},
],
[
'label' => '是否审核',
'attribute' => 'driver_check_uptime',
'filter' => UserInfo::$isCheck,
'format' => 'raw',
'value' => function($data) {
return $data->is_black_list ? '<span class="text-danger">是</span>' : '<span class="text-success">否</span>';
},
],
[
'attribute' => 'source',
'filter' => Constants::$requestSourceTypes,
'value' => function($data) {
return Constants::$requestSourceTypes[$data->source];
},
],
['class' => 'yii\grid\ActionColumn','template' => '{view} {update}'],
],
]); ?>
</div>
共 1 个回答
-
应该是 这个属性吧
https://www.yiiframework.com/doc/api/2.0/yii-grid-gridview#$filterOnFocusOut-detail$filterOnFocusOut public property (available since version 2.0.16)
Whatever to apply filters on losing focus. Leaves an ability to manage filters via yiiGridView JSpublic boolean $filterOnFocusOut = true
tinymeng 北京
注册时间:2018-03-05
最后登录:2024-10-24
在线时长:36小时43分
最后登录:2024-10-24
在线时长:36小时43分
- 粉丝7
- 金钱25065
- 威望20
- 积分25625