handle no pagination

This commit is contained in:
Aaron Kable
2026-01-17 18:22:42 +08:00
parent fec35dbb1b
commit e9fdc89069
2 changed files with 17 additions and 1 deletions

View File

@@ -174,6 +174,10 @@ class DataTablesView(View):
draw = int(table_conf["draw"])
start = int(table_conf["start"])
length = int(table_conf["length"])
if length <= 0:
logger.warning(
"Using no pagination is not recommended for server side rendered datatables"
)
limit = start + length
@@ -192,7 +196,10 @@ class DataTablesView(View):
)
# build output
for row in qs[start:limit]:
if length > 0:
qs = qs[start:limit]
for row in qs:
ctx = {"row": row}
row = []
for t in self.columns:

View File

@@ -267,3 +267,12 @@ class TestDataTables(TestCase):
response.setup(request)
data = json.loads(response.get(request).content)["data"]
self.assertEqual(len(data), 19)
def test_view_cc_no_pagination(self):
self.get_params["length"] = "-1"
self.client.force_login(self.user)
request = self.factory.get('/fake-url/', data=self.get_params)
response = TestView()
response.setup(request)
data = json.loads(response.get(request).content)["data"]
self.assertEqual(len(data), 20)