Last active
November 4, 2023 09:44
-
-
Save tguruslan/5b18aca2c74ee9ee2cd834bc6eefc90e to your computer and use it in GitHub Desktop.
failter and sort virtual date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
[ | |
'class'=>'\kartik\grid\DataColumn', | |
'attribute'=>'date_tmp', | |
'filterType'=>GridView::FILTER_DATE, | |
'format'=>'raw', | |
'filterWidgetOptions'=>[ | |
'pluginOptions'=>['format'=>'dd.mm.yyyy'], | |
], | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function rules() | |
{ | |
return [ | |
... | |
[['date_tmp'], 'safe'], | |
]; | |
} | |
public function getDate_tmp(){return ($this->date?date('d.m.Y',$this->date):null);} | |
public function setDate_tmp($value){$this->date = strtotime($value);} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public $date_tmp; | |
public function rules() | |
{ | |
return [ | |
... | |
[['date_tmp'], 'safe'], | |
]; | |
} | |
public function search($params) | |
{ | |
... | |
$dataProvider->sort->attributes['date_tmp'] = [ | |
'asc' => ['date' => SORT_ASC], | |
'desc' => ['date' => SORT_DESC], | |
'default' => SORT_ASC | |
]; | |
$query->andFilterWhere([ | |
'between','date',strtotime($this->date_tmp),strtotime($this->date_tmp.' +1day') | |
]); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment