Skip to content

Instantly share code, notes, and snippets.

@tguruslan
Last active November 4, 2023 09:44
Show Gist options
  • Save tguruslan/5b18aca2c74ee9ee2cd834bc6eefc90e to your computer and use it in GitHub Desktop.
Save tguruslan/5b18aca2c74ee9ee2cd834bc6eefc90e to your computer and use it in GitHub Desktop.
failter and sort virtual date
<?php
[
'class'=>'\kartik\grid\DataColumn',
'attribute'=>'date_tmp',
'filterType'=>GridView::FILTER_DATE,
'format'=>'raw',
'filterWidgetOptions'=>[
'pluginOptions'=>['format'=>'dd.mm.yyyy'],
],
],
<?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);}
<?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