我正在使用 Kartik GridView 来显示数据。在状态栏中,我设置了 FILTER_SELECT2 。
这是我的gridview的视图。
当我从过滤器下拉列表中选择状态时,该表格将刷新,但未显示基于所选状态的数据(无任何更改)。
这是我的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表的视图
这是我的searchModel的代码:
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
时限。
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,
]
]);
答案 0 :(得分:1)
删除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,
]);
}