下拉筛选列中的 Kartik GridView Pjax 错误
Kartik GridView Pjax error in dropdown filter column
我正在使用 Kartik GridView 来显示数据。在状态列中,我设置了 FILTER_SELECT2.
这是我的 gridview 的视图。
当我 select 来自过滤器下拉列表的状态时,table 将刷新但它没有显示基于 selected 状态(没有变化)。
这是我的代码 index.php
<?php
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\widgets\Pjax;
use yii\helpers\ArrayHelper;
use app\modules\vatout\models\VatoutStatus;
use app\modules\vatout\assets\Asset;
Asset::register($this);
?>
<div class="vatout-faktur-out-index">
<?php Pjax::begin() ?>
<?=
GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'pjax' => true,
'columns' => [
['class' => 'yii\grid\SerialColumn',
],
[
'attribute' => 'invoice',
'value' => function($data) {
return $data->invoice;
;
},
'hAlign' => 'center',
'width' => '175px',
],
[
'attribute' => 'date',
'value' => function($data) {
return $data->date;
},
'hAlign' => 'center',
'width' => '110px',
],
[
'attribute' => 'prod_code',
'value' => function($data) {
return $data->prod_code;
},
'hAlign' => 'center',
'width' => '185px',
],
['class' => 'kartik\grid\FormulaColumn',
'attribute' => 'amount',
'format' => ['currency'],
'value' => function($data) {
return $data->amount;
},
'mergeHeader' => true,
'hAlign' => 'center',
'width' => '160px',
],
[
'attribute' => 'comp_name',
'value' => function($data) {
return $data->comp_name;
},
'hAlign' => 'center',
'width' => '320px',
],
[
'attribute' => 'scan_date',
'value' => function($data) {
return $data->scan_date;
},
'mergeHeader' => true,
'hAlign' => 'center',
'width' => '80px',
],
[
'attribute' => 'is_exported',
'width' => '80px',
'value' => function ($model, $key, $index, $widget) {
return $model->isExported->name;
},
'filterType' => GridView::FILTER_SELECT2,
'filter' => ArrayHelper::map(VatoutStatus::find()->orderBy('id')->asArray()->all(), 'id', 'name'),
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Any Status']
],
],
'toolbar' => [
],
'panel' => [
'type' => GridView::TYPE_SUCCESS,
'before' => '<p><button type="button" onclick="getRows()" class="btn btn-success"><i class="glyphicon glyphicon-export"></i> DOWNLOAD CSV</button></p>', //IMPORTANT
],
'persistResize' => false,
'toggleDataOptions' => ['minCount' => 10]
]);
?>
<?php Pjax::end() ?>
这是VatoutStatus的视图Table
这是我的搜索模型的代码:
public function search($params)
{
$query = VatoutStatus::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'disposal_id' => $this->disposal_id,
'user_id' => $this->user_id,
'parent_id' => $this->parent_id,
'date' => $this->date,
'amount' => $this->amount,
'updated_at' => $this->updated_at,
'created_at' => $this->created_at,
'is_exported' => $this->is_exported,
]);
$query->andFilterWhere(['like', 'comp_name', $this->comp_name])
->andFilterWhere(['like', 'updated_by', $this->updated_by])
->andFilterWhere(['like', 'created_by', $this->created_by]);
return $dataProvider;
}
我已经按照文档中的说明设置了 'pjax' => true,
。
我从我的浏览器检查元素中得到这个错误:
为什么会出现这个错误? SO 中的一些问题和另一篇文章说,因为超时。但是我不知道如何增加pjax
时间限制。
为什么我的 PJAX 出错了?以及如何解决?
已解决
public function actionIndexSparepart() {
$userId = Yii::$app->user->id;
$searchModel = new VatoutFakturOutSearch();
$dataProvider = new \yii\data\ActiveDataProvider([
'query' => VatoutFakturOut::find()->
where(['user_id' => $userId, 'vatout_type' => 1]),
'pagination' => [
'pageSize' => 100,
]
]);
删除 pjax
<?php // Pjax::begin() ?>
...
.
.
.
<?php //Pjax::end() ?>
并改变动作动作
public function actionindex....(){
$searchModel = new vatoutfakturoutSearch();
$searchModel->user_id = $user_id;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('userindex', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
我正在使用 Kartik GridView 来显示数据。在状态列中,我设置了 FILTER_SELECT2.
这是我的 gridview 的视图。
当我 select 来自过滤器下拉列表的状态时,table 将刷新但它没有显示基于 selected 状态(没有变化)。
这是我的代码 index.php
<?php
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\widgets\Pjax;
use yii\helpers\ArrayHelper;
use app\modules\vatout\models\VatoutStatus;
use app\modules\vatout\assets\Asset;
Asset::register($this);
?>
<div class="vatout-faktur-out-index">
<?php Pjax::begin() ?>
<?=
GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'pjax' => true,
'columns' => [
['class' => 'yii\grid\SerialColumn',
],
[
'attribute' => 'invoice',
'value' => function($data) {
return $data->invoice;
;
},
'hAlign' => 'center',
'width' => '175px',
],
[
'attribute' => 'date',
'value' => function($data) {
return $data->date;
},
'hAlign' => 'center',
'width' => '110px',
],
[
'attribute' => 'prod_code',
'value' => function($data) {
return $data->prod_code;
},
'hAlign' => 'center',
'width' => '185px',
],
['class' => 'kartik\grid\FormulaColumn',
'attribute' => 'amount',
'format' => ['currency'],
'value' => function($data) {
return $data->amount;
},
'mergeHeader' => true,
'hAlign' => 'center',
'width' => '160px',
],
[
'attribute' => 'comp_name',
'value' => function($data) {
return $data->comp_name;
},
'hAlign' => 'center',
'width' => '320px',
],
[
'attribute' => 'scan_date',
'value' => function($data) {
return $data->scan_date;
},
'mergeHeader' => true,
'hAlign' => 'center',
'width' => '80px',
],
[
'attribute' => 'is_exported',
'width' => '80px',
'value' => function ($model, $key, $index, $widget) {
return $model->isExported->name;
},
'filterType' => GridView::FILTER_SELECT2,
'filter' => ArrayHelper::map(VatoutStatus::find()->orderBy('id')->asArray()->all(), 'id', 'name'),
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Any Status']
],
],
'toolbar' => [
],
'panel' => [
'type' => GridView::TYPE_SUCCESS,
'before' => '<p><button type="button" onclick="getRows()" class="btn btn-success"><i class="glyphicon glyphicon-export"></i> DOWNLOAD CSV</button></p>', //IMPORTANT
],
'persistResize' => false,
'toggleDataOptions' => ['minCount' => 10]
]);
?>
<?php Pjax::end() ?>
这是VatoutStatus的视图Table
这是我的搜索模型的代码:
public function search($params)
{
$query = VatoutStatus::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'disposal_id' => $this->disposal_id,
'user_id' => $this->user_id,
'parent_id' => $this->parent_id,
'date' => $this->date,
'amount' => $this->amount,
'updated_at' => $this->updated_at,
'created_at' => $this->created_at,
'is_exported' => $this->is_exported,
]);
$query->andFilterWhere(['like', 'comp_name', $this->comp_name])
->andFilterWhere(['like', 'updated_by', $this->updated_by])
->andFilterWhere(['like', 'created_by', $this->created_by]);
return $dataProvider;
}
我已经按照文档中的说明设置了 'pjax' => true,
。
我从我的浏览器检查元素中得到这个错误:
为什么会出现这个错误? SO 中的一些问题和另一篇文章说,因为超时。但是我不知道如何增加pjax
时间限制。
为什么我的 PJAX 出错了?以及如何解决?
已解决
public function actionIndexSparepart() {
$userId = Yii::$app->user->id;
$searchModel = new VatoutFakturOutSearch();
$dataProvider = new \yii\data\ActiveDataProvider([
'query' => VatoutFakturOut::find()->
where(['user_id' => $userId, 'vatout_type' => 1]),
'pagination' => [
'pageSize' => 100,
]
]);
删除 pjax
<?php // Pjax::begin() ?>
...
.
.
.
<?php //Pjax::end() ?>
并改变动作动作
public function actionindex....(){
$searchModel = new vatoutfakturoutSearch();
$searchModel->user_id = $user_id;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('userindex', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}