M
M
Mikha Pankratov2016-09-06 15:33:09
JavaScript
Mikha Pankratov, 2016-09-06 15:33:09

How to make all filters work in a group?

Good afternoon,

I'm doing just such a thing on the client, loadMore AND 3 filters) The
question is how to make them work together?
Deleal through ActiveDataProvider and jquery Here are

a couple of pieces of code)

Select

<?php $this->registerJS('
    $("select").click(function(){
        var param = $(\'meta[name=csrf-param]\').attr("content");
        var token = $(\'meta[name=csrf-token]\').attr("content");

        $.ajax({
                type: "post",
                data: {
                    "matches": $(this).val(),
                    param: token
                },
                success: function(data){
                    $(".list-view").append(data);
//                    if (page >= pageCount){ $(\'#js-load-more\').hide(); }
                }
            });
    });
');


And the loadSea itself
<?php $this->registerJS('
   $('#js-load-more').click(function(){
            $.ajax({
                type: "post",
                data: {
                    "page": page+1,
                    param: token
                },
                success: function(data){
                    page++;
                    loadingFlag = false;
                    $('#listView').append(data);
                    if (page >= pageCount){ $('#js-load-more').hide(); }
                }
            });
        });


Probably still the action itself
public function actionIndex(){
        $query = User::find()->where(['rights' => new Expression('IFNULL(rights,0) | '.UserRightsEnum::BGO_PASS)]);

        $this->processPageRequest('page');
        $provider = new ActiveDataProvider([
            'query' => $query,
            'sort'=> ['defaultOrder' => ['id'=> \Yii::$app->request->post('matches') ? SORT_DESC : SORT_ASC]],
            'pagination' => [
                'pageSize' => 6,
                'page' =>\Yii::$app->request->get('page'),
            ],
        ]);

        if (\Yii::$app->request->isAjax){
            return $this->renderPartial('_list', [
                'dataProvider' => $provider,
            ]);
        } else {
            return $this->render('index', [
                'dataProvider' => $provider,
            ]);
        }

    }


Everyone who has come across, I will be grateful if you help) I can’t figure it out

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-09-06
@webinar

It's easier with pjax. But do not update the content, but add below.

N
Nikita, 2016-09-09
@bitver

When clicking in ajax.data, in addition to the token and the page, pass the filter parameters. And in the controller, everything is according to the load () standard and the rest seems to be ready for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question