V
V
Victor Umansky2017-09-10 14:20:10
Yii
Victor Umansky, 2017-09-10 14:20:10

Sorting broken with pjax?

Hello everyone, guys, help me fix the sorting when I did the sorting (I was helped here) since there was no layout, it worked and I started to stretch the layout and then it started)
index

<div class="wrapp-prod">
                <div class="filters-index-block">
                    <div class="block">
                        <label for="sort">Сортировать по:</label>
                        <?php echo $this->render('_sort', ['model' => $searchModel]); ?>
                    </div>
                </div>

                <?php Pjax::begin(['formSelector' => '#form_sort_item_category']) ?>
                <?= ListView::widget([
                    'dataProvider' => $dataProvider,
                    'layout' => "{items}\n<nav aria-label=\"#\" class=\"prod-pagination\">{pager}</nav>",
                    'summary' => '',

                    'options' => [
                        'tag' => 'div',
                        'class' => 'content-prod-grid',
                    ],

                    'itemOptions' => [
                        'tag' => 'div',
                        'class' => 'item-prod',
                    ],

                    'pager' => [
//                        'maxButtonCount' => 5,
                        'options'=>['class'=>'pagination'],
                        'prevPageLabel' => Html::img('/web/images/pagination-arrow.png', ['alt' => '']),
                        'nextPageLabel' => Html::img('/web/images/pagination-arrow-1.png', ['alt' => '']),


                        'linkOptions' => ['class' => 'page-link'],

                    ],


                    'itemView' => function ($model, $key, $index, $widget) {
                        return $this->render('list', ['model' => $model]);
                    },
                    'emptyText' => 'Категория пуста'
                ]) ?>
                <?php Pjax::end(); ?>
            </div>

_sort file
<select class="selectpicker sort">

    <?php $form = ActiveForm::begin([
        'id' => 'content-prod-grid',
        'method' => 'get',
    ]) ?>
    <?= $form->field($model, 'sort')->dropDownList(
        [
            '-price' => 'От дорогих к дешевым',
            'price' => 'От дешёвых к дорогим',
            'popular' => 'От А до я',
            'rating' => 'От Я до а'
        ],
        [
            'prompt' => 'По умолчанию',
            'onchange' => '$(this).closest("form").submit()',
            'name' => 'sort',
        ])->label('')
    ?>
    <?php $form = ActiveForm::end() ?>
</select>

search model ProductSeedsSearch
верху    public $sort;

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
            'sort' => new Sort([
                'defaultOrder' => [
                    'id' => SORT_DESC
                ],
                'attributes' => [
                    'id',
                    'price',
                ]
            ]),
        ]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-09-10
@Uman

You have #form_sort_item_category in pjax, but the form itself is 'id' => 'content-prod-grid',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question