GridView中使用DatePicker选择日期 [ 未指定版本 ]
use yii\grid\GridView;
use kartik\widgets\DatePicker;
view
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// ......
[
'attribute' => 'created_at',
'value' => function($model){
return date('Y-m-d', $model->created_at);
},
'filter' => DatePicker::widget([
'model' => $searchModel,
'attribute' => 'created_at',
'name' => 'created_at',
'readonly' => true,
'options' => ['placeholder' => 'Select issue date ...'],
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy-mm-dd',
'todayHighlight' => true
]
]),
],
// ......
],
]); ?>
在search方法中添加搜索条件
if ($this->created_at) {
$createdAt = strtotime($this->created_at);
$createdAtEnd = $createdAt + 24*3600;
$query->andWhere("product.created_at >= '{$createdAt}' AND product.created_at <= '{$createdAtEnd}'");
}
void
注册时间:2016-05-15
最后登录:2018-06-12
在线时长:10小时30分
最后登录:2018-06-12
在线时长:10小时30分
- 粉丝2
- 金钱10
- 威望10
- 积分210
共 0 条评论