M
M
Maxim Grechushnikov2015-03-31 12:56:50
Yii
Maxim Grechushnikov, 2015-03-31 12:56:50

Yii2: How to make custom filters for ListView/GridView?

It is necessary to make a conclusion of cards of goods/users. Filters need to be moved outside the grid/list view. but within pjax
How can *view be manipulated?

<?php \yii\widgets\Pjax::begin(); ?>
сюда фильтры можно вынести
<?= \yii\widgets\ListView::widget([
  'dataProvider' => $provider,
  'itemOptions' => ['class' => 'item'],
  'summary'=>'',
  'itemView' => function ($model, $key, $index, $widget) {
      return $this->render('_item', ['model' => $model]);
    },
]) ?>
<?php \yii\widgets\Pjax::end(); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zohei, 2015-04-09
@maxyc_webber

use yii\widgets\Pjax;
use yii\widgets\PjaxAsset;
PjaxAsset::register($this);

$this->registerJs(<<<JS
$(document).on('change', '#provider', function(e) {
    $.pjax({
        timeout: 4000,
        url: $('#filter-form').attr('action'),
        container: '#list-view',
        fragment: '#list-view',
        data: {provider: this.options[this.selectedIndex].value},
   });
});
JS
, yii\web\View::POS_END);

<?=Html::beginForm(Url::current(), 'GET', ['id'=>'filter-form']);?>
     <?=Html::activeDropDownList($model, 'provider', Provider::items(), ['id'=>'provider']); ?>
<?=Html::endForm(); ?>

<?php \yii\widgets\Pjax::begin(); ?>
<?= \yii\widgets\ListView::widget([.....]) ?>
<?php \yii\widgets\Pjax::end(); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question