yajra / laravel-datatables

jQuery DataTables API for Laravel
https://yajrabox.com/docs/laravel-datatables
MIT License
4.75k stars 861 forks source link

fix: make query for filteredRecords when totalRecords was manually set #3157

Closed JurianArie closed 2 months ago

JurianArie commented 2 months ago

Hi, we always use setTotalRecords(0) since we only show the filtered records count. After upgrading to Laravel 11 we noticed that our pagination stopped working. This seems to be caused by c37494f11f0b6e198fa7428edd38e5d5b2a6d9de. This PR changes the logic to always query the filtered count if the total count was set manually.

yajra commented 2 months ago

Thank you for the PR, I will review this as soon as I can.

yajra commented 2 months ago

@Arkhas it seems like the PR you've sent is being reverted on this change. Would you mind reviewing and approving this? Thanks!

JurianArie commented 2 months ago

@yajra I have added an assertion to show that the optimization @Arkhas did still works. This PR is not a revert of his work, only a bug fix.

yajra commented 2 months ago

I confirmed one less query after the patch. This is a good optimization trick for large datasets. Thanks!

Released on 11.1.3 :rocket: