void 2016-12-21 13:56:10 5078次浏览 0条评论 4 0 0
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}'");
}
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册