You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am still not sure if this is a bug, but the Yii2 search used to work fine with this approach for years. In the application I am working on, we used the following approach, but after the upgrade to version 2.0.50, the total count in the data provider object is not correct anymore.
What steps will reproduce the problem?
public function search() {
$query = User::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 20,
'page' =>!Yii::$app->request->isConsoleRequest ? (int) Yii::$app->request->getQueryParam('page', 0) : 0,
]
]);
$this->load($params);
if (!$this->validate()) {
$query->andWhere("1=0");
return $dataProvider;
}
//Apply additional filters to the query
return $dataProvider;
}
What is the expected result?
I expect the correct total count value to be calculated with applied query filters.
What do you get instead?
I got a total count of all records in the table without query filters applied to the query.
Additional info
In the example above, we pass the pagination configuration when the ActiveDataProvider instance is created. The pagination object will be created immediately, and the total count in the Pagination object will also be populated using the $query passed at that point.
The issue will not be present if we do not pass the pagination configuration to the data provider.
As far as I see, this problem was caused by the following commit 90c0eb0
I know how to work around the current issue, but I wanted to bring up this topic because I am afraid it will affect many applications.
Q
A
Yii version
2.0.50
PHP version
8.2
Operating system
Ubuntu 22
The text was updated successfully, but these errors were encountered:
srdjan92
changed the title
Bug: Pagination total count is incorrect
Bug: DataProvider total count is incorrect
Jun 25, 2024
I am still not sure if this is a bug, but the Yii2 search used to work fine with this approach for years. In the application I am working on, we used the following approach, but after the upgrade to version 2.0.50, the total count in the data provider object is not correct anymore.
What steps will reproduce the problem?
What is the expected result?
I expect the correct total count value to be calculated with applied query filters.
What do you get instead?
I got a total count of all records in the table without query filters applied to the query.
Additional info
In the example above, we pass the pagination configuration when the
ActiveDataProvider
instance is created. The pagination object will be created immediately, and the total count in thePagination
object will also be populated using the$query
passed at that point.The issue will not be present if we do not pass the pagination configuration to the data provider.
As far as I see, this problem was caused by the following commit 90c0eb0
I know how to work around the current issue, but I wanted to bring up this topic because I am afraid it will affect many applications.
The text was updated successfully, but these errors were encountered: