-
-
Notifications
You must be signed in to change notification settings - Fork 853
Prevent unwanted count query #3169
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
Conversation
|
Can we please merge this asap? @yajra |
|
The changes look good but ci/cd checks are failing. Can you please fix it? Thanks! |
|
This breaks my use case wherein we only want to make a query for the filtered count but never for the total count. |
Are you sure? This is exactly what I am intending as well.
|
|
|
Finally fixed all the checks 😄 |
|
I tested the changes locally, and I can confirm that it breaks my use case.
This assumes that filters are applied. If no filters are applied, it will result in |
|
I am confused; If there are no filters Can you please send your DataTable so that I can test as well? |
|
The test cases before reflected the correct behavior. Here, the users table contains 20 records, and we manually set the total records to zero. The filtered records should still be 20. laravel-datatables/tests/Integration/QueryDataTableTest.php Lines 462 to 464 in 178a25d
laravel-datatables/tests/Integration/QueryDataTableTest.php Lines 34 to 42 in 178a25d
|
|
Exactly what I mean. Having |
|
You should think of |
Case 1: (Your case)// Total 2500: / Filtered: 100
$dataTable->setTotalRows(0)->make();This should result in: Case 2: (My case)// Total 2500: / Filtered: 100
$dataTable->setTotalRows(2500)->make();This should result in: Am I correct about this? |
1. Fresh setup of using the quick start guideGuide: https://yajrabox.com/docs/laravel-datatables/master/quick-starter As you can see when I apply your change the pagination is broken. |
|
Fixed via #3170 |















The only reason we're using
setTotalRecordsis to prevent the count query.Even though we're seting the
totalRecordswe also need to setperformedTotalRecordsCountso that;IF -> there are filters applied to the query (any kind of search)
THEN -> don't perform total count AGAIN
There was an update about this topic recently: 9f7169a
Sadly it didn't cover all the cases.
Here is the related code in QueryDataTable#L275