issue with gridview and datepicker

hi!

Im new in Yii2.0 and I need help in using gridview and datepicker. I have below code in my index.php.

<?= GridView::widget([

    'dataProvider' =&gt; &#036;dataProvider,


    'filterModel' =&gt; &#036;searchModel,


    'columns' =&gt; [


        ['class' =&gt; 'yii&#092;grid&#092;SerialColumn'],


    [


	'class' =&gt; 'yii&#092;grid&#092;DataColumn',


        'label' =&gt; 'Sales Date',


	'value' =&gt; function (&#036;data) {


		&#036;sales_dt=&#036;data['fdate'];


		return Yii::&#036;app-&gt;formatter-&gt;asDate(strtotime(&#036;sales_dt), 'php:d-m-Y');


		},


	'filter'=&gt; DatePicker::widget(array(


		'name'  =&gt; 'sales_date',


		'model' =&gt; &#036;searchModel,


		'attribute'=&gt;'fdate',


		'dateFormat' =&gt; 'php:d-m-Y',


		), true),


    ],


        [


	'class' =&gt; 'yii&#092;grid&#092;ActionColumn',


	'template' =&gt; '{view}',


	'buttons' =&gt; [


		'view' =&gt; function (&#036;url, &#036;model, &#036;key) {


	                       return Html::a('&lt;span class=&quot;glyphicon glyphicon-eye-open&quot;&gt;&lt;/span&gt;', &#036;url, [


			           'title' =&gt; Yii::t('yii', 'View'),


			          ]);


				},


		],


     ],


    ],


]); ?&gt;

and i would like to know how to do sort and filter for the date column. Thanks for any help! :)

below is my modelsearch function:

public function search($params)

{


    &#036;query = Sales::find();





    &#036;dataProvider = new ActiveDataProvider([


        'query' =&gt; &#036;query,


    ]);


	


	&#036;dataProvider-&gt;setSort([


		'defaultOrder' =&gt; [


			'fdate' =&gt; SORT_DESC,


			'fcheck' =&gt; SORT_DESC,


			'fdesc1' =&gt; SORT_ASC,


		],


	]);





    if (&#33;(&#036;this-&gt;load(&#036;params) &amp;&amp; &#036;this-&gt;validate())) {


        return &#036;dataProvider;


    }





    &#036;query-&gt;andFilterWhere([


        'sales_key' =&gt; &#036;this-&gt;sales_key,


        'create_dt' =&gt; &#036;this-&gt;create_dt,


        'update_dt' =&gt; &#036;this-&gt;update_dt,


    ]);





    &#036;query-&gt;andFilterWhere(['like', 'sales_status_fl', &#036;this-&gt;sales_status_fl])


        -&gt;andFilterWhere(['like', 'fdate', &#036;this-&gt;fdate]);





    return &#036;dataProvider;


}

first create function which convert fetched value in form of date format in Search model.


private function dbDateSearch($value)

{

            if($value != "" && preg_match('/^(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-[0-9]{4}$/', $value,$matches))

                return date("Y-m-d",strtotime($matches[0]));

            else

                return $value;

}

than use that function in Filter value like …


$query->andFilterWhere(['like', 'sales_status_fl', $this->sales_status_fl])

      ->andFilterWhere(['like', 'fdate', $this->dbDateSearch($this->fdate)]);

after check out with filtering the date value in GridView…

Happy Codding. :)

Hi!

Thanks a lot it works!