[FIX] Count filtered records before applying the limit

This commit is contained in:
Peter Pfeufer
2026-01-20 23:13:18 +01:00
parent c19f7e6e79
commit 843c3ccf9a
2 changed files with 14 additions and 1 deletions

View File

@@ -195,6 +195,9 @@ class DataTablesView(View):
*self.get_order(table_conf)
)
# Get the count after filtering
qs_count = qs.count()
# build output
if length > 0:
qs = qs[start:limit]
@@ -210,7 +213,7 @@ class DataTablesView(View):
datatables_data = {}
datatables_data['draw'] = draw
datatables_data['recordsTotal'] = self.get_model_qs(request, *args, **kwargs).all().count()
datatables_data['recordsFiltered'] = qs.count()
datatables_data['recordsFiltered'] = qs_count
datatables_data['data'] = items
return JsonResponse(datatables_data)