Skip to content

Commit d3b4d3a

Browse files
authored
Merge pull request #3007 from Arkhas/master
Prevent the filteredCount() query if no filter is applied to the initial query
2 parents 48b4ea8 + 6e43204 commit d3b4d3a

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/QueryDataTable.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,35 @@ public function keepSelectBindings(): static
205205
return $this;
206206
}
207207

208+
/**
209+
* Perform column search.
210+
*
211+
* @return void
212+
*/
213+
protected function filterRecords(): void
214+
{
215+
$initialQuery = clone $this->query;
216+
217+
if ($this->autoFilter && $this->request->isSearchable()) {
218+
$this->filtering();
219+
}
220+
221+
if (is_callable($this->filterCallback)) {
222+
call_user_func($this->filterCallback, $this->resolveCallbackParameter());
223+
}
224+
225+
$this->columnSearch();
226+
$this->searchPanesSearch();
227+
228+
// If no modification between the original query and the filtered one has been made
229+
// the filteredRecords equals the totalRecords
230+
if ($this->query == $initialQuery) {
231+
$this->filteredRecords ??= $this->totalRecords;
232+
} else {
233+
$this->filteredCount();
234+
}
235+
}
236+
208237
/**
209238
* Perform column search.
210239
*

tests/Integration/QueryDataTableTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function it_can_set_total_records()
2525
$crawler->assertJson([
2626
'draw' => 0,
2727
'recordsTotal' => 10,
28-
'recordsFiltered' => 20,
28+
'recordsFiltered' => 10,
2929
]);
3030
}
3131

@@ -36,7 +36,7 @@ public function it_can_set_zero_total_records()
3636
$crawler->assertJson([
3737
'draw' => 0,
3838
'recordsTotal' => 0,
39-
'recordsFiltered' => 20,
39+
'recordsFiltered' => 0,
4040
]);
4141
}
4242

0 commit comments

Comments
 (0)