gridview 如何实现区间查询 [ 2.0 版本 ]
比如,查询在5.1~5.20日之间的全部记录。
共 3 个回答
-
不想写的话添加一个插件
composer require kartik-v/yii2-date-range
views
use kartik\daterange\DateRangePicker; echo GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], .... [ 'attribute' => 'created_at', 'format' => ['date', 'php:Y-m-d H:i'], 'filter' => DateRangePicker::widget([ 'model' => $searchModel, 'attribute' => 'created_at', 'convertFormat' => true, 'pluginOptions' => [ 'timePickerIncrement' => 30, 'locale' => [ 'format' => 'Y-m-d', ], 'opens' => 'left' ] ]), ], ], ]);
search model
if (!empty($this->created_at)) { $created_at = explode(' - ', $this->created_at); $query->andFilterWhere(['between', 'created_at', strtotime($created_at[0]), strtotime('+1 day', strtotime($created_at[1])) - 1]); }
duandaoke
注册时间:2015-02-08
最后登录:2018-09-12
在线时长:10小时53分
最后登录:2018-09-12
在线时长:10小时53分
- 粉丝0
- 金钱10
- 威望0
- 积分110