Press "Enter" to skip to content

Yii 2 – Filter Date in Grid View

0

Last updated on 19 Oct 2019

Bagaimana cara Filter Tanggal di Grid View

Yii2 Framwoek

Di Grid View:

use kartik\grid\GridView;

[
  'attribute' => 'updated_at',
  'format' => 'date',
  'filterType' => GridView::FILTER_DATE,
     'filterWidgetOptions' => [
     'size' => 'xs',
     'pluginOptions' => [
        'format' => 'dd-M-yyyy',
        'autoWidget' => true,
        'autoclose' => true,
        'todayHighlight' => true
      ]
   ],
],

Di Model Search:

public function rules() {
   [['page', 'updated_at'], 'safe']
}

Di public function search()

if (!empty($this->updated_at)) {
 $this->updated_at = date('d-m-Y', strtotime($this->updated_at));
 }

->andFilterWhere(['=', 'FROM_UNIXTIME(updated_at, "%d-%m-%Y")', $this->updated_at])