Row Group include count of full dataset instead of just rows in current page
Row Group include count of full dataset instead of just rows in current page
I'm building a button to toggle rowgrouping on and off, and like the idea of adding the count into the title as shown in this example:
https://datatables.net/extensions/rowgroup/examples/initialisation/endRender.html
startRender: function ( rows, group ) {
return group +' ('+rows.count()+')';
},
The trouble is the count is only for what is shown on the current page, not in the full dataset. Is there a good way to change the count to account for the full set?
This question has an accepted answers - jump to answer
Answers
This example from this thread should do what you want.
Kevin
Thanks Kevin, seems like the right path, I altered for what I am trying but I am getting an error that the group is not defined:
I didn't think it needed to be as it is being passed no? I'm sure i am missing something silly here.
You have
startRender: function ( rows, groups )
. Thereturn data[4] == group ? true : false;
is intended to use the second variable in the parameters. Changegroups
togroup
.Kevin
Ok, so that solved the group issue, but I still can't get to the count for the full dataset of a group instead of what is on a page.
Are you using server side processing? If so that why because only the data on the page is at the client.
If not please provide a link to your page or a test case showing the issue.
Kevin
No I am not, I just got it to work actually, one hiccup that I am sorting through. here is where i am:
The hiccup is the group for blanks does not work because the group name is different., so it always shows up as 0. Thoughts?
Not sure what you mean by blanks. Can you provide a test case so we can see your data?
Kevin
The column that is being used for rowgrouping does not require data, so there is always a group of blanks/no data.
Trying something like this currently to no avail:
All I can suggest is use console.log statements or the browser's debugger to see what the value of
group
is for the empty group anddata[ 'nest' ]
. You may need to change this code to handle that situation:Kevin
Looks like we cross posted
I added a couple of empty office columns to this example and it works without code changes:
http://live.datatables.net/piwahega/1/edit
My above comment still stands. You need to validate what the
group
anddata['nest']
values are when the column is empty.Kevin
Yeah, I've been doing that, and the blanks don't seem to show any value in the return, as in they aren;t there at all. I have since worked out a conditional for when blank to just not include the number as for how this is being used it does not matter.