Skip to content

Wrong DataProvider->totalCount #17093

@anditza

Description

@anditza

Wrong DataProvider->totalCount

What steps will reproduce the problem?

$query = MyModel::find();
$dataProvider = new ActiveDataProvider(['query' => $query);
$dataProvider->pagination->pageSize = 30;
//    Now $dataProvider->totalCount is set because of BaseDataProvider::getPagination()
$query->andFilterWhere(['number' => $this->number]);
//    From now on totalCount is NOT updated to consider this condition and any other conditions added before feeding it to a GridView and rendering.

What is the expected result?

totalCount should be set only when DataProvider gets to be used to fetch and render data.
Up to version 12.0.15 DataProvider pagination could be invoked and set before setting all its query conditions and afterwards totalCount was calculated correctly as expected.

What do you get instead?

DataProvider totalCount is wrong - total number of rows in the table!! - doesn't care about query conditions added after invoking $dataProvider->pagination.

Additional info

Related issue: #16891

Q A
Yii version 2.0.16
PHP version 7.*
Operating system Windows/Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions