File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ class QueryDataTable extends DataTableAbstract
25
25
*/
26
26
protected bool $ prepared = false ;
27
27
28
+ /**
29
+ * Flag to check if the total records count query has been performed.
30
+ */
31
+ protected bool $ performedTotalRecordsCount = false ;
32
+
28
33
/**
29
34
* Query callback for custom pagination using limit without offset.
30
35
*
@@ -157,6 +162,20 @@ public function prepareQuery(): static
157
162
return $ this ;
158
163
}
159
164
165
+ /**
166
+ * Count total items.
167
+ */
168
+ public function totalCount (): int
169
+ {
170
+ if ($ this ->totalRecords !== null ) {
171
+ return $ this ->totalRecords ;
172
+ }
173
+
174
+ $ this ->performedTotalRecordsCount = true ;
175
+
176
+ return $ this ->totalRecords = $ this ->count ();
177
+ }
178
+
160
179
/**
161
180
* Counts current query.
162
181
*/
@@ -253,7 +272,7 @@ protected function filterRecords(): void
253
272
254
273
// If no modification between the original query and the filtered one has been made
255
274
// the filteredRecords equals the totalRecords
256
- if ($ this ->query == $ initialQuery ) {
275
+ if ($ this ->query == $ initialQuery && $ this -> performedTotalRecordsCount ) {
257
276
$ this ->filteredRecords ??= $ this ->totalRecords ;
258
277
} else {
259
278
$ this ->filteredCount ();
You can’t perform that action at this time.
0 commit comments