Skip to content

Commit 9f7169a

Browse files
authored
Make query for filteredRecords when totalRecords was manually set
1 parent 393296d commit 9f7169a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/QueryDataTable.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class QueryDataTable extends DataTableAbstract
2525
*/
2626
protected bool $prepared = false;
2727

28+
/**
29+
* Flag to check if the total records count query has been performed.
30+
*/
31+
protected bool $performedTotalRecordsCount = false;
32+
2833
/**
2934
* Query callback for custom pagination using limit without offset.
3035
*
@@ -157,6 +162,20 @@ public function prepareQuery(): static
157162
return $this;
158163
}
159164

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+
160179
/**
161180
* Counts current query.
162181
*/
@@ -253,7 +272,7 @@ protected function filterRecords(): void
253272

254273
// If no modification between the original query and the filtered one has been made
255274
// the filteredRecords equals the totalRecords
256-
if ($this->query == $initialQuery) {
275+
if ($this->query == $initialQuery && $this->performedTotalRecordsCount) {
257276
$this->filteredRecords ??= $this->totalRecords;
258277
} else {
259278
$this->filteredCount();

0 commit comments

Comments
 (0)