Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Yii2 jui datepicker to filter field in GridView

I'm using the same code as I used to add in ActiveForm, but it doesn't work:

What i sthe correct way to add jui datepicker in filter field for gridview?

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'list_id',
            [
                'attribute' => 'channel',
                'value' => 'channel.title',
            ],
            [
                'attribute' => 'list_date',
                'value' => 'list_date',
                'filter' => \yii\jui\DatePicker::widget(\yii\jui\DatePicker::className(), ['language' => 'ru', 'dateFormat' => 'dd-MM-yyyy']),
            ],
            'make_date',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
like image 663
LIAL Avatar asked Dec 19 '14 09:12

LIAL


1 Answers

I tried this and works fine:

[
    'attribute' => 'updated_at',
    'value' => 'updated_at',
    'filter' => \yii\jui\DatePicker::widget([
        'model'=>$searchModel,
        'attribute'=>'updated_at',
        'language' => 'ru',
        'dateFormat' => 'dd-MM-yyyy',
    ]),
    'format' => 'html',
],

Then, you must add this line to your Search Model:

$query->andFilterWhere([

    ...

    'DATE(updated_at)' => $this->updated_at,
]);

Make sure the date formats are identical.

like image 109
Ahmed Ismail Avatar answered Oct 10 '22 23:10

Ahmed Ismail