row group with subtotals
row group with subtotals
MadMax76 Posts: 142Questions: 31Answers: 1
edited March 2021 in Priority support
is it possible to have a table like this:
but with not only the number of rows but also the sum of the salarys; e.g. "Edinburgh (10 people; total salary $ 456.902)"?
This question has an accepted answers - jump to answer
This discussion has been closed.
Checkout this example.
tried to implement this in my code, but I don't get it running. Here without sums:
Adding the lines from your example stops it from wokring completely:
You are getting this error in the browser's console:
When summing a column using
columns.renderyou will need to use
cells().render(). See Colin's example from this thread.
so why are you working on sunday?
I dot get it, I tried to implement this into
Is it normal that I can not use a number for the cells, but have ti give the full name - is that because of ajax?
And an extra question: the consol of my firefox, having errors and warnings to be shown, doesn't show me that error - how do you do that?
You are getting this error:
Instead of trying to use
this.api()just use the
tablevariable you have. Try this:
It was my mistake. I thought you were using
columns.renderfor that column,
Sorry, I don't understand your question.
We are very close!!!
After also adding the "intval", now the example shows a number - but the total of the page, which is my fault as I gave it that name. But I am looking for the total only of a group.
And the collapsing works for the second level ,not for the (now added) first level of the groups.
And another (i hope last one for this topic) question: Can I start the table with all rows collapsed (showing only sums?
Thanks a lot!
See if this thread helps.
You can. Start with this thread to see how to expand and collapse rowGroups with a click event. There are some threads that show how to start with all the groups collapsed.
maybe it is too late... bnoth does not work...
And I have another step to go then to implement a second-level-group with the first(0)-column....
Not sure what you mean both don't work. Please provide specific details of how to see the problems.
You will find more threads on this too :-)
All of these questions have been discussed many times on the forum. Guess someone should write a technote on these subjects
now in "more" detail:
example is here:
'1. despite having the following code in there it starts with rows expanded.
'2. expand/collaps works on 2. level (e.g. 310000), but not on first level (e.g. 0)
does always bring a result of Zero
I do find discussions on rowgroup, but none working example with multiple groups AND subtotals. This here https://datatables.net/forums/discussion/47614/row-grouping-and-its-subtotal-for-multiple-level seems to be based on a out-dated multi-level-grouping, and also is not showing a running example.
Place a debugger breakpoint on line 3 of this code:
You will see it doesn't execute. The reason is you are fetching data via ajax (asynchronous process) and the Datataable initialization isn't complete when this code is executed. Move it inside
You have this code to
I think this is from one of the examples but the code has
not notso it doesn't seem to be making any changes. Start by placing a debugger breakpoint on this line (line 115 in your example):
This will allow you to debug the values of the
collapsedGroupsobject and the
collapsedvariable. My guess is you need to replace the
You are using
.pluck(5)but are using object based data. You will want to use `.pluck('V_Zahllauf_Details.Zahlungsbetrag') instead.
thanks for your patience.
I put the first part into "initcomplete", now it fires, but still does not work.
In the second code I removed all !!, which makes no change. having only one ! "looks good", but: it removes the second level and when clcking first, time, all OTHER groups are expanded, completely wrong way....
and for the pluck I tried
All changes were made in
Have you tried debugging the
collapsedGroupsvariable to see what is happening? There is nothing specific to Datatables about that code. Its just a matter of getting
collapsedGroupsto properly track the state of the rowGroup.
ITs hard to debug this without access to the code to make changes. I would start by removing
.sum()and see what
filteredDatacontains. Make sure the proper rows are returned for each group. Maybe nothing is returned. Or maybe you need to do some debugging of the
sum()plugin. Looks like the values are strings, maybe the sum() plugin isn't handling it correctly.
If you want to build a simple test case with a sample of your data (not 171 rows but just a few) we can do more to help with debugging since we can work with the code.
Sorry, I cant provide a test case. I tried to start with some example, as that seems easiest way to do that. I do not think you can have ajax-sources there (at least I haven't seen one up to now), so I chose this one:
which works perfectly apart from not having sub-totals (or totals)
as soon as I put this into it:
the datatable stops working. SAme with
....also kills it.
Thanks for the test case! It was missing the HTML tab so I copied it from a previous version:
tablevariable is not available, ie, doesn't have the Datatables API, until after the Datatable has initialized. In
initCompleteyou can get an instance of the API using
this.api(). In RowGroup you can get is using
initCompleteyou will need to call
draw()to redraw the table with the
collapsedGroupsthat is built. Also change
rowGroup.startRenderto get the last column.
Your working time is worse then mine!!!! sunday, midnight,....
Thanks for your effort, but only level 1- group is hidden (acutally the details are there, only the middle-level is "missing".
Also the sum is the same in every sub-total - I guess it is the sum of the complete table.
Thank you, Max
This solves the problem with the group count: http://live.datatables.net/gudaquvi/1/edit .
I wasn't clear about the "level-1" group, could you explain that please.
great for the sums!!!!
All rows should be collapsed from start; So i get to see only the two lines "Sonya Frost" and "Tiger Nixon" with their total counts/sums.
But i see row-groups for webmaster ("Sonya Frost"), the arcdate ("2020-06-19") and the details - only the "A-plus"(offer-name) is hidden until I click "Sonya Frost" one.
Also when clicking on "Sonya Frost", only the offer_name-subtotal vanishes, but the other details stay there. In opposite when clicking "Royal Queen" it does what I think it should to - all sub-groups and details vanish
The key to this is how collapsed groups is built. It relies on combining the group names per level to build the key to access the proper collapsedGroup object. I changed the code in
initCompleteto iterate all rows to build the collapsed groups. Added a couple console.log statements so you can see what is happening.
YES your example is exactly what I need!!!! Great to see that is possible.
I tried to adapt the code for my needs with ajax-datasource, sonehow this again does not work .I guesss the reason is you call the data like this:
whilst I use the ajay inside the datatable.
So my hopefully really last question: how do i get this into the data-variable?
The data source doesn't matter. You don't need to use a
data-variable. We moved the code into
initCompleteto run after the Datatables is initialized due to the asynchronous Ajax request.
i am VERY sorry, I stil ldont get it to work:
again no sums and not collapsed.... As far as I can say it is a exact copy of the code in
just data-source and column-names changed...
The console output shows this for the rowGroup dataSrc:
It builds the collapsedGroup that looks like this which is not correct:
The loop building this looks like this:
Basically it looks like this
key += data["V_Zahllauf_Details.ZVK_KONTOZVSPERRE"];which won't work. You will need to split the key at the period.
See if this works, I didn't test it so you may need to make adjustments:
WE HAVE DONE IT!!!!
I changed the datasource and eliminated the "V_Zahllauf_Details." - part, now it works!!!!
Thanks a lot for your never-ending patience!