-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix #20055 causes bad result for pagination using for example gridview #20175
Comments
…od executable. Add internal cache for ActiveDataProvider and SqlDataProvider.
@samdark it seems since 2.0.50 the active data provider is broken when using pagination and/or sort params: yii\base\InvalidConfigException: The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses. in /var/www/html/vendor/yiisoft/yii2/data/ActiveDataProvider.php:164 this code breaks with the above stack trace in version 2.0.50 return new ActiveDataProvider([
'pagination' => [
'defaultPageSize' => 75,
],
'query' => $query
->select([SchemaRow::tableName().'.id', 'title', 'subtitle', 'is_visible'])
->byLikeTitle($model->query)
->isNotTrashed()
->andFilterWhere([SchemaRow::tableName().'.id' => $model->ids])
->bySchemaId($id),
'sort' => [
'defaultOrder' => [
'title' => SORT_ASC,
],
],
]); removing the sort/and or pagination definition and it works again. We had to downgrad to 2.0.49 in order to get the app working. change the code to: return new ActiveDataProvider([
'query' => $query
->select([SchemaRow::tableName().'.id', 'title', 'subtitle', 'is_visible'])
->byLikeTitle($model->query)
->isNotTrashed()
->andFilterWhere([SchemaRow::tableName().'.id' => $model->ids])
->bySchemaId($id),
]); for testing, and it works also in 2.0.50 php 8.3.4 |
@samdark not sure its related to be honest. but i also have problems with the active data provider with latest version. Let me know if i should create a fresh issue. |
Workaround is to make sure the configuration array contains |
i tested the fix in dev-master, seems to work. thanks 👍 |
Thanks for verifying it. |
…th GridView" This reverts commit 3fa2d61.
What steps will reproduce the problem?
When creating the dataprovider, for example:
$provider = new ActiveDataProvider([
'query' => ...,
'pagination' => [...]
]);
Setting the 'pagination' calls the setPagination() function, which now directly calls the getTotalCount() function, which calls the prepareTotalCount() function.
Now the value for $_totalCount will be queried from the database.
When using a GridView with a SearchModel, the search parameters for the query are loaded in a later stage.
The search parameters can cause for a different number of rows to be returned.
The prepareTotalCount() is not called again, because $_totalCount is already set.
The pagination bar now works with a completely wrong count value. (for example, displays more pages than there actually are)
Calling prepareTotalCount() again is not a solution, the count on a big table can be very expensive.
Additional info
The text was updated successfully, but these errors were encountered: