我已经在yii2中开发了应用程序,并且为网格视图中的过滤器使用了Kartik日期范围选择器扩展程序。
我遇到了以下问题。
当我为开始日期和结束日期选择不同的日期时,它将起作用。 例如开始日期5和结束日期10
当我选择第二天作为开始日期和结束日期时,它将起作用。 例如开始日期6和结束日期6
当我选择今天的开始日期和结束日期时,它将不起作用。 例如开始日期5和结束日期5
示例代码。
<?php
$gridColumns = [
[
'class' => 'kartik\grid\SerialColumn'
],
[
'label' => Yii::t('app', "Created At"),
'attribute' => 'created_at',
'value' => function ($model) {
if (extension_loaded('intl')) {
return $model->created_at;
} else {
return $model->created_at;
}
},
'filter' => DateRangePicker::widget(
[
'model' => $searchModel,
'attribute' => 'created_at',
'convertFormat' => true,
'presetDropdown' => false,
'pluginOptions' => [
'locale' => [
'format' => 'Y-m-d'
]
]
]
)
],
[
'attribute' => 'branch_id',
'value' => 'branch.name',
'filter' => Html::activeDropDownList(
$searchModel,
'branch_id',
ArrayHelper::map(Branch::find()->asArray()->all(), 'id', 'name'),
['class' => 'form-control', 'prompt' => 'Select Branch']
)
],
[
'attribute' => 'user_id',
'value' => 'user.firstname',
'filter' => Html::activeDropDownList(
$searchModel,
'user_id',
ArrayHelper::map(User::find()->asArray()->all(), 'id', 'firstname'),
['class' => 'form-control', 'prompt' => 'Select User']
)
],
[
'attribute' => 'order_status',
'format' => 'html',
'filter' => ["0" => "Completed", "1" => "Refund", "2" => "Cancel"],
'value' => function ($model) {
if ($model->order_status == '1') {
return '<span class="label bg-red">Refund</span>';
} else if ($model->order_status == '2') {
return '<span class="label bg-yellow">Cancel</span>';
} else {
return '<span class="label bg-blue">Completed</span>';
}
}
],
[
'attribute' => 'created_from',
'format' => 'html',
'value' => function ($model) {
if ($model->created_from == '1') {
return '<span class="">WEB<small>';
} else if ($model->created_from == '2') {
return '<span class="">IOS<small>';
} else if ($model->created_from == '3') { //MARKAS
return '<span class="">ANDROID<small>';
}
}
],
[
'attribute' => 'pax',
'format' => 'html',
'value' => function ($model) {
$setting = common\constants\EstablishmentConfiguration::activeSetting();
$type = '';
$paxFlag = '0';
if (!empty($setting)) {
$type = $setting->establishment_type;
$paxFlag = $setting->enable_pax;
}
if ($type == 'restaurant' && $paxFlag == '1') {
return $model->pax;
} else {
return '--';
}
}
],
//'pax',
'sub_total',
'discount',
'tax',
'grand_total',
[
'class' => 'yii\grid\ActionColumn',
'header' => Yii::t('app', 'Action'),
'template' => '{view} {movetofack}',
'contentOptions' => ['style' => 'width:10%'],
'buttons' => [
'view' => function ($url, $model) {
return Html::a(
'<span class="glyphicon glyphicon-eye-open"></span>',
['view', 'id' => $model->id],
[
'class' => 'btn btn-xs btn-warning',
'title' => 'View',
'data-skin' => 'skin-warning'
]
);
},
'movetofack' => function ($url, $model) {
return Html::a(
'<span class=" fa fa-trash"></span>',
[
'movettotrash', 'id' => $model->id
],
[
'class' => 'btn btn-xs btn-warning',
'title' => 'Fack Record',
'data-skin' => 'skin-warning',
'data' => [
'confirm' => Yii::t('app/msg', 'Are you sure this is fake record? would you like to move to trash this order?'),
'method' => 'post'
]
]
);
}
]
]
];