Revision #202 has been created by rackycz on Jun 30, 2020, 10:41:16 PM with the memo:
GridView + DatePicker
« previous (#201) next (#203) »
Changes
Title
unchanged
Yii v2 snippet guide
Category
unchanged
Tutorials
Yii version
unchanged
2.0
Tags
unchanged
tutorial,beginner,yii2
Content
changed
[...]
```php
function getDatepickerFilter($searchModel, $attribute) {
$name = basename(get_class($searchModel)) . "[$attribute]";
$result = \yii\jui\DatePicker::widget(['language' => 'en', 'dateFormat' => 'php:Y-m-d', 'name'=>$name, 'value'=>$searchModel->$attribute, 'options' => ['class' => 'form-control'] ]);
if (trim($searchModel->$attribute)!=='') {
$result = '<div style="display:flex;flex-direction:column">' . $result
. '<div class="btn btn-danger btn-xs glyphicon glyphicon-remove" onclick="$(this).prev(\'input\').val(\'\').trigger(\'change\')"></div></div>';
}
return $result;
}
// ...
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
// ...
[
[
'attribute' => 'myDateCol',
'value' => 'myDateCol',
'label'=>'My date label',
'filter' => getDatepickerFilter($searchModel,'myDateCol'),
'format' => 'html'
],
// ...
```