Answer the question
In order to leave comments, you need to log in
How to filter date for created_at column in gridview?
I tried 2 ways, this is to change the parameters received in get requests. But I realized that they are not changeable. Then I made a new variable for the columns, the minus is that when you filter, nothing is displayed.
User models
public $date_registration;
public function rules()
{
return [
....
[['auth_date', 'date_registration'], 'safe'],
...
];
}
public function attributeLabels()
{
return [
....
'date_registration' => 'Дата регистрации'
];
}
public $date_registration;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
...
[['date_registration'], 'date', 'format' => 'php:Y-m-d']
];
}
$query->andFilterWhere([
...
'created_at' => $this->date_registration ? strtotime($this->date_registration) : null,
...
]);
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
...
[
'attribute' => 'date_registration',
'label' => 'Дата регистрации',
'format' => 'datetime',
'value' => function($date) {
return $date->created_at;
},
'filter' => Html::input('date', 'UsersSearch[date_registration]'),
],
...
],
]); ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question