Pagination issue with search in gridview

using Yii2, I’m making the three Models of relationship: FinlegadoTitulo,FinlegadoTituloParcelaand FinlegadoTituloParcelaCentroDeCusto.

  • A title has N portions

  • A portion has 1 Cost Center

The Models of relationship is being done as follows:

FinlegadoTitulo



    public function getFinlegadoTituloParcelas()

    {

        return $this->hasMany(FinlegadoTituloParcela::className(), ['finlegado_titulo_id' => 'id'])->orderBy('numero_parcela');

    }

FinlegadoTituloParcela



    public function getFinlegadoTituloParcelaCentroDeCusto()

    {

       return $this->hasOne(FinlegadoTituloParcelaCentroDeCusto::className(), ['id' => 'finlegado_titulo_parcela_centro_de_custo_id']);

    }


    public function getFinlegadoTitulo()

    {

        return $this->hasOne(FinlegadoTitulo::className(), ['id' => 'finlegado_titulo_id']);

    }

FinlegadoTituloParcelaCentroDeCusto



  public function getFinlegadoTituloParcelas()

    {

        return $this->hasMany(FinlegadoTituloParcela::className(), ['finlegado_titulo_parcela_centro_de_custo_id' => 'id']);

    }



With this structure, I’m trying to search for a title where your parcels has the center of XXX ** ** cost, and the Model FinLegadoTituloSearch with the following method:




    public function search($params)

    {

        $query = FinlegadoTitulo::find();


        $dataProvider = new ActiveDataProvider([

            'query' => $query,

        ]);


        $dataProvider->setSort(['defaultOrder' => ['data_vencimento' => SORT_DESC]]);

        

        if (!($this->load($params) && $this->validate())) {

            return $dataProvider;

        }


        $query->joinWith('FinlegadoTituloParcelaCentroDeCusto');


        $query->andFilterWhere([

            'id' => $this->id,

            'data_cadastro' => $this->data_cadastro,

            'data_emissao' => $this->data_emissao,

            'data_competencia' => $this->data_competencia,

            'quantidade_parcelas' => $this->quantidade_parcelas,

            'valor_original' => $this->valor_original,

            'data_vencimento' => $this->data_vencimento,

            'n_pagamento' => $this->n_pagamento,

            'finlegado_titulo_tipo_doc_id' => $this->finlegado_titulo_tipo_doc_id,

            'finlegado_cliente_id' => $this->finlegado_cliente_id,

        ]);

        $query->andFilterWhere(['>', 'data_cadastro', $this->data_de]);

        $query->andFilterWhere(['<', 'data_cadastro', $this->data_ate]);


        $query->andFilterWhere(['like', 'documento', $this->documento])

            ->andFilterWhere(['like', 'tipo', $this->tipo])

            ->andFilterWhere(['like', 'status', $this->status])

            ->andFilterWhere(['like', 'historico', $this->historico])

            ->andFilterWhere(['like', 'alterado', $this->alterado]);


        return $dataProvider;

    }

And it does not return me the titles surveyed by cost center XXX

What do you mean by "cost center XXX"?

In view, a gridview list all results of my model FinlegadoTitulo, with default pagination size (20 items). When i use the filter for model FinlegadoTituloSearch, the pagination of gridview list only some items. The images below show the problem:

List all results:

http: //i.imgur.com/ ilftcqM.png

after filter:

http: //i.imgur.com/ epMY5VY.png

FinlegadoTituloSearch


    public function search($params)

    {

        $query = FinlegadoTitulo::find();


        $dataProvider = new ActiveDataProvider([

            'query' => $query

        ]);


        $dataProvider->setSort(['defaultOrder' => ['data_vencimento' => SORT_DESC]]);

        

        if (!($this->load($params) && $this->validate())) {

            return $dataProvider;

        }


        $query->joinWith('finlegadoTituloParcelas');


        $query->andFilterWhere([

            'id' => $this->id,

            'data_cadastro' => $this->data_cadastro,

            'data_emissao' => $this->data_emissao,

            'data_competencia' => $this->data_competencia,

            'quantidade_parcelas' => $this->quantidade_parcelas,

            'valor_original' => $this->valor_original,

            'data_vencimento' => $this->data_vencimento,

            'n_pagamento' => $this->n_pagamento,

            'finlegado_titulo_tipo_doc_id' => $this->finlegado_titulo_tipo_doc_id,

            'finlegado_titulo_parcela_centro_de_custo_id' => $this->finlegado_titulo_parcela_centro_de_custo_id,

            'finlegado_cliente_id' => $this->finlegado_cliente_id,

        ]);

        $query->andFilterWhere(['>', 'data_cadastro', $this->data_de]);

        $query->andFilterWhere(['<', 'data_cadastro', $this->data_ate]);


        $query->andFilterWhere(['like', 'documento', $this->documento])

            ->andFilterWhere(['like', 'tipo', $this->tipo])

            ->andFilterWhere(['like', 'status', $this->status])

            ->andFilterWhere(['like', 'historico', $this->historico])

            ->andFilterWhere(['like', 'alterado', $this->alterado]);


        return $dataProvider;

    }

@edit

in test, when i put the code


$query->prepare(Yii::$app->db->queryBuilder);

the pagination works fine. What hell is going on? Someone can tell me?

[color="#006400"]/* Two topics merged.

Please don’t start another topic with the same subject */[/color]