SearchPanes: Neither countFiltered nor cascadePanes work with server-side processing
SearchPanes: Neither countFiltered nor cascadePanes work with server-side processing
Link to test case: https://comprehensibleinputwiki.com/ciwlibrary/test_case.php
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Client-side code:
document.addEventListener('DOMContentLoaded', function () {
let table = new DataTable('#library-table', {
dom: 'Plfrtip',
serverSide: true,
ajax: {
url: "newvidadmin.php",
type: "GET"
},
deferRender: true,
"columns": [
{ "data": "vid" },
{ "data": "title" },
{ "data": "channelTitle" },
{ "data": "level" ,
"class": "level" },
{ "data": "language" ,
"class": "language" },
{ "data": "enabled" ,
"class": "enabled" },
],
searchPanes: {
cascadePanes: true,
viewTotal: true,
i18n: {
count: '{total}',
countFiltered: '{shown} / {total}'
}
},
"columnDefs": [
{
"targets": [5], "orderable": false
},
{
"targets": 3,
"createdCell": function (td, cellData, rowData, row, col) {
$(td).attr('data-field', 'level');
}
},
{
"targets": 4,
"createdCell": function (td, cellData, rowData, row, col) {
$(td).attr('data-field', 'language');
}
},
{
"targets": 5,
"createdCell": function (td, cellData, rowData, row, col) {
$(td).attr('data-field', 'enabled');
}
},
]
});
});
I can't get the filtered count to show up when using the Editor PHP library. It shows the total count for each entry just fine, but adding a filter doesn't show an updated filtered count.
Edit: The filtered count is being sent over with the JSON from the server, the client just isn't using it.
This question has an accepted answers - jump to answer
Answers
Can you show me the server-side code you are using?
This is an example of SearchPanes with cascade enabled and server-side processing.
Allan
I don't see anything wildly off from the example which would make it not work.
Me neither! What version of the libraries are you using? You can check in
Editor.php
and search for theversion
property.What does the JSON return show?
Thanks,
Allan
Sure, the version is 2.1.2. And here is some of the JSON. I just removed some of the data from two of the columns, and the debug section to make it shorter, but it has the essentials. This is after clicking "Comprehensible Chinese" in the channelTitle Pane. As you can see on line 53 for
Chinese
, there are 110 rows filtered, out of 689 total, but in the SearchPane, it still says 689.Any ideas for this? I've been trying, and can't figure out why the client ignores
count
in the json.New test case link: https://comprehensibleinputwiki.com/ciwlibrary/testcase5.php
Ok, I think I'm getting somewhere in hunting it down. In this function of datatables.js:
The stuff after the
if(pane.s.colOpts.show)
never runs. If I force it to run by doing if(true), then the panels show{count} / 357
. As in thecount
variable doesn't get replaced. But at least collapse works if I do that.Could you add this to your DataTables initialisation:
I don't know why that appears to be needed. SearchPanes is due for an overhaul as soon as I'm finished the current batch of work.
Allan
Ok, I added that to my actual page, not the test page, since I was messing with that datatables.js code for the test page and I might have changed important things.
Anyway, here's the link:
https://comprehensibleinputwiki.com/ciwlibrary/vidadmin.php
After adding that, collapse works, but not count:
Thanks! I think I see the issue - it should be
{shown}
in the string rather than{count}
. The docs for this parameter don't mention{count}
.Allan
Oh, wow, I don't know where I got
count
. Thank you for spotting that!