【问题标题】:Kartik GridView Pjax error in dropdown filter column下拉过滤器列中的 Kartik GridView Pjax 错误
【发布时间】:2017-07-11 11:58:41
【问题描述】:

我使用 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 Table的视图

这是我的 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' =&gt; 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,
        ]
    ]);

【问题讨论】:

    标签: php gridview yii2 pjax


    【解决方案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,
            ]);
    
    }
    

    【讨论】:

    • 我已经尝试了您的建议,但他们还没有解决我的问题。我有很多问题,首先是buy_search 来自哪里,然后我不知道我应该把你建议的代码放在哪里。谢谢
    • 我试过了,但它给了我同样的错误。是否可能是因为容器 id 的问题?
    • 明天(15/7/2017)格林威治标准时间 3.30。有电报吗?请给我发消息@amirajloo。我可以从下午 13 点开始回复。
    • 好的,我已经添加并通过电报给你发了一条消息:)
    猜你喜欢
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多