From 4a9653b408238daa7f7bceadd80eca0ef601e4e1 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 3 Apr 2024 14:50:41 +0200 Subject: [PATCH] docs: add example with the searchPanes.cascadePanes feature By default, the item counters in the search panes are not updated if a filter is applied. Reference: https://datatables.net/reference/feature/searchPanes.cascadePanes --- README.md | 32 ++++++++++++++++++- .../repository/DataTablesRepositoryImpl.java | 3 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b17116..2d5234d 100644 --- a/README.md +++ b/README.md @@ -667,7 +667,37 @@ $(document).ready(function() { data : 'status' }] }); -} +}); +``` + +With the [`searchPanes.cascadePanes`](https://datatables.net/reference/feature/searchPanes.cascadePanes) feature: + +```js +$(document).ready(function() { + var table = $('table#sample').DataTable({ + ajax : '/data/users', + serverSide: true, + dom: 'Pfrtip', + columns : [{ + data : 'id' + }, { + data : 'mail' + }, { + data : 'position', + searchPanes: { + show: true, + } + }, { + data : 'status', + searchPanes: { + show: true, + } + }], + searchPanes: { + cascadePanes: true, + }, + }); +}); ``` Regarding the deserialization issue detailed [above](#step-6---fix-the-serialization--deserialization-of-the-query-parameters), here is the compatibility matrix: diff --git a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java index 0c955d9..b1bb1dc 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java +++ b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java @@ -118,6 +118,9 @@ private SearchPanes computeSearchPanes(DataTablesInput input, Specification s this.entityManager.createQuery(query).getResultList().forEach(objects -> { String value = String.valueOf(objects[0]); long count = (long) objects[1]; + // FIXME the number of items after filtering is the same as the total number of items, so the 'searchPanes.viewTotal' + // feature will not work properly. Fixing this would require two distinct queries, one with filtering and the other + // without. Reference: https://datatables.net/reference/feature/searchPanes.viewTotal items.add(new SearchPanes.Item(value, value, count, count)); });