-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subtotals #26
Comments
This isn't supported at the moment, no, but it's a good idea. It would enable expanding/collapsing (#25). The right way to implement this would be to first modify the PivotData structure to contain subtotal information encoded somehow, and then to modify the default table renderer. |
Right, I have a project that will need this functionality, and I guess this implementation will not occur soon, then can you give some tip to help me developing this? When ready I post the changes. |
It's been 4 months. Any progress on this? Because I need to use this in a project. If anyone started yet, I'll give it a try. |
I don't believe anyone is working on this at the moment. My recommendation is that you start by making the minimal possible changes to the Once that's done, you can develop a new Renderer based on the Table Renderer which displays subtotals. I would be happy to accept that as a separate renderer in its own file, but probably not as an extensive set of modifications to the built-in Table Renderer. Hope this makes sense, let me know if I can provide any pointers! |
I even tried, but considering my best programming language is not JavaScript, I developed this in PHP. If you want, I can post the code. |
@nicolaskruchten I'll start then. I'll try to make it like igniteui pivotgrid does. However, the problem is I don't know coffeescript. (even changing id to classes was pain for me :) @rafaels86 could do somehow send me PHP code for a start point for me? |
Yes, follows: function PivotTable($arrDados, $arrRows, $arrCols, $arrValues) { $htmlCols = array(); $arrChaveColAnt = array(); for ($i = 0; $i < count($arrLabelsCol); $i++) { //monta as colunas de título $cols = split("|", $arrLabelsCol[$i]); $chaveCol = ""; $arrColspan = array(); //guarda qtas colunas devem ser expandidas for ($col = 0; $col < count($cols); $col++) { if ($chaveCol) $chaveCol .= "|"; if (!array_key_exists($col, $arrColspan)) $arrColspan[$col] = 1; if (count($arrValues) > 1) if (!array_key_exists(count($cols), $htmlCols)) $htmlCols[count($cols)] = "\n\n"; $chaveCol .= $cols[$col]; $colspan = count($arrValues);
// if ($_SESSION['SGUSUARIO'] == 'ADMIN') $htmlRows .= "\n"; $arrChaveColAnt = array(); for ($j = 0; $j <= count($arrLabelsCol); $j++) { //valores - vai uma coluna a mais do que existiria para fazer o total $cols = split("|", $arrLabelsCol[$j]); $chaveCol = ""; $arrLastCol = array(); $lastCol = false; for ($col = 0; $col < count($cols); $col++) { if ($chaveCol) $chaveCol .= "|"; $chaveCol .= $cols[$col]; for ($val = 0; $val < count($arrValues); $val++) { if (($arrChaveColAnt[$col] != $chaveCol and $arrChaveColAnt[$col])) { //coluna de subtotal $lastCol = $col == count($cols)-1 and count($arrValues) > 1; //quando existe mais de um campo de valor não é possível mostrar diretamente o subtotal do campo e o valor final, pois ficaria o total do primeiro campo de valor no subtotal do segundo campo de valor $chaveVal = $chaveRow."#".$arrChaveColAnt[$col]."#".$arrValues[$val]; $valor = FormataNumeroMoeda($pivotSubtotal[$chaveVal]); $htmlRows .= ""; } if ($col == count($cols)-1) { //só escreve no último nível $chaveVal = $chaveRow."#".$arrLabelsCol[$j]."#".$arrValues[$val]; if (array_key_exists($chaveVal, $pivot)) $valor = FormataNumeroMoeda($pivot[$chaveVal]); else if (array_key_exists($chaveVal, $pivotSubtotal)) $valor = FormataNumeroMoeda($pivotSubtotal[$chaveVal]); else $valor = ""; $td = ""; if ($lastCol) $arrLastCol[$val] = $td; else $htmlRows .= $td; } else { if ($val == count($arrValues)-1) //só atualiza a chave depois de montar todos os campos de valor $arrChaveColAnt[$col] = $chaveCol; } } } } if ($lastCol) for ($val = 0; $val < count($arrLastCol); $val++) { $htmlRows .= $arrLastCol[$val]; } $htmlRows .= "\n"; } }
}
|
I can't use this code properly. Could you paste your code on viper-7 and click "paste" button then give me the link of result page? |
I think that is it: http://viper-7.com/0tyjmj |
anyone who was able to get through this? |
Well, I said I wanted to but I've been so busy with the projects at work. It looks like I can't start for now or a couple of weeks. |
Hi Guys, has anyone able to solve this one? |
@santoshdhanshetti I tried but had to stop as I'm busy with some other projects. |
Any progress? |
I decided to put subtotals between parenthesis on each row/col header... not much of an elegant solution (and different from the target of this discussion) but it may help someone: 1 - Put ids and classes on needed headers. I did it by changing the code where the class th.className = "pvtColLabel"
# Identify cells that need subtotals
if parseInt(j) < colAttrs.length-1
# Put class and id to be able to iterate through them then
th.className += " colLab"
th.id = "colLab_" + j + "_" + i
th.setAttribute("colspan", x)
th.className = "pvtRowLabel"
# Identify cells that need subtotals
if parseInt(j) < rowAttrs.length-1
# Put class and id to be able to iterate through them then
th.className += " rowLab"
th.id = "rowLab_" + j + "_" + i
th.setAttribute("rowspan", x) 2 - Then, since I wanted to show the totals not only in # Place subtotals where needed
placeSubtotals = (headerClass) ->
headerType = (if headerClass.indexOf("row") > -1 then "row" else "col")
# In case there is more than one pivot table in page, it's useful to put them in divs with unique ids :)
#containerId = pivotTable.closest("table").parent().attr("id")
container = $(result);
classIds = container.find("th." + headerClass).map((i) ->
@id
)
headerIds = classIds.get()
if headerIds.length > 1
classSpans = container.find("th." + headerClass).map((i) ->
if headerType is "row"
$(this).attr "rowspan"
else
$(this).attr "colspan"
)
headerSpans = classSpans.get()
# Order headerIds for rows, to make subtotals calculation easier (could be made for columns too)
if headerType is "row"
orderedHeaderIds = []
orderedHeaderSpans = []
j = 0
while j < headerIds.length
index = headerIds[j].split("_")[1]
i = j
while i < headerIds.length
# If it's not in the ordered list, find out if it must go next
if orderedHeaderIds.indexOf(headerIds[i]) is -1 and headerIds[i].split("_")[1] is index
orderedHeaderIds.push headerIds[i]
orderedHeaderSpans.push headerSpans[i]
# Save some loops when done
break if headerIds.length is orderedHeaderIds
i++
# Save some loops when done
break if headerIds.length is orderedHeaderIds
j++
# Copy results
headerIds = orderedHeaderIds
headerSpans = orderedHeaderSpans
# Iterate through every header putting subtotals
lastSpan = 0
oldIndex = 0
j = 0
while j < headerIds.length
# Reset indexes on every header row/col change
index = headerIds[j].split("_")[1]
unless oldIndex is index
lastSpan = 0
oldIndex = index
# Add totals for every header
acum = 0
limit = lastSpan + parseInt(headerSpans[j])
i = lastSpan
while i < limit
acum += container.find("[data-for=" + headerType + i + "]").data("value")
i++
oldHtml = container.find("#" + headerClass + "_" + oldIndex + "_" + lastSpan).html()
container.find("#" + headerClass + "_" + oldIndex + "_" + lastSpan).html oldHtml + " (" + acum + ")"
lastSpan += parseInt(headerSpans[j])
j++
return
placeSubtotals "colLab"
placeSubtotals "rowLab"
return result |
Hey, anyone who was able to do this in another row? |
hi nicolas great work done by you..:) |
I'm not actively working on this feature, no. |
anyone manage to do this? :) |
@nicolaskruchten, Thanks a lot for such a useful library. I have added the support for roll-up summary (sub-total rows) using aggregators and renderer concepts . Its available at SubTotals branch of the fork that I have made Would like to receive your comments/feedback from friends here before I send the pull request. I plan to add collapse-and-expand feature on top of this. Thanks. |
goooood work Nagaraj :) |
@nagarajanchinnasamy do you have a sample of how to use your SubTotals branch. Are there any settings to turn it on or off? |
@vivianjayakaran there are no settings as of now... its directly built into the code. No new code or modification to existing code is needed. You can try any of the provided To try, please download the code from the link below and run the examples locally under a web-server: |
@nagarajanchinnasamy thanks for this contribution! My feedback is as follows:
|
@nicolaskruchten Thanks for your feedback.
|
@nicolaskruchten , friends... I have further enhanced subtotal_renderers with both row-wise and column-wise subtotals. Also added Collapse/Expand functionality for rows. Collapse/Expand for column subtotals is under construction.... Please check Subtotals branch. and provide your feedback. Steps to use:
|
@nagarajanchinnasamy There is an error in computation of "Sum as Fraction of Rows" and "Count as Fraction of Rows". Do you know how to correct this? |
I think the "Totals" of Subtotals don't include in computation element in aggregator "fraction Of", cause i check in "subtotal.html" the subtotal "Female" don't divided with itself but with subtotal of "NDP in Quebec", etc... etc... Hope this will pinpoint the problem... Anyway thanks for this great work... |
@ahmad003 Thanks for the feedback... I will look into this issue and get back. Thanks again. |
@ahmad003 I do not see any issue with the aggregators. For e.g., in the picture shown below, after selecting Sum as Fraction of Total and Age, the overall total is 15603 and for Females in Age Bin 60, the subtotal value is 883. Converting this to percentage ((883/15603)*100)) yields 5.7% as shown rightly in the pivot. Or, am I missing something? Please confirm. |
Thank you @nagarajanchinnasamy for reply my question... And, yes, for Sum as Fraction of Total there is no error, but if you use Sum as Fraction of Rows, you will see there is an error like this... |
And if you continue to make subtotals for column, most likely there will be an error in Sum as Fraction of Columns... Thank you once again for fast reply... I hope this will help you in developing this project... |
@ahmad003 , Yes... I see the issue now. Let me check and get back to you. Thanks for clarification. |
Thank you once again @nagarajanchinnasamy... You're Awesome... For my reference, is there a way to make default expand/collapse to expand,.. And for future development, I think it's necessary to make tool to expand/collapse all rows, to hide/show subtotals for row and column... when your data so many, you don't want to click one by one to expand/collapse all rows, isn't it... Anyway Great Work !! |
@ahmad003 Thanks :-) Yes, I plan to add I have enabled issues tab in the forked repository here in case if you want to discuss |
@ahmad003 I have added an option
Default behavior is to expand all rows. Please check Thanks for your feedback. |
@ahmad003 in addition to the I will also see if I can provide a function to show/hide subtotals |
@nagarajanchinnasamy, its awesome. |
@ahmad003 Thanks. % of Parent Row/Column is a good suggestion. Willl add and let you know. Thanks again. |
@nagarajanchinnasamy, can subtotals generate without UI? |
@ahmad003 sorry I did not understand what you mean by:
|
@nagarajanchinnasamy, Sorry.. I mean to change this code in example/subtotal.html in line 38
to
but when i try, the subtotals didn't generate.. |
@ahmad003 got it. I will check. Thanks for the feedback. |
Are you gona PR this on the nicolaskruchten repo? |
@nagarajanchinnasamy I've put some thought into how we can modify this library to allow your fine work to be compatible. My proposal is that we accept a new parameter which would allow the developer to override the |
Definitely @nicolaskruchten.... My pleasure 👍 Please confirm once this change is done. I will modify the code accordingly and submit a PR. |
@nicolaskruchten, as u had suggested, I've created Submitted PR #506. Please review and let me know of your feedback. Also, the special character used for displaying triangleLink does not seem to appear correctly on my browser (chrome). Screenshot: |
@nicolaskruchten , @ahmad003 , @anandakumarramaswamy , @vivianjayakaran and friends, happy to inform you that Subtotal.js is available for download as an NPM module or Bower component. Subtotal.js is hosted in GitHub as pivottable-subtotal-renderer @nicolaskruchten , In setting up Subtotal.js, I have shamelessly copied the structure, style and some portions of text and code as is from Pivottable.js repository. Hope you don't mind. Thanks again to all of you for your feedback and support 👍 |
All right, I think we can finally consider this issue resolved! The official answer in the FAQ is now "use Subtotal.js" :) |
Is there a way to create subtotals on rows and columns when exists more than one field in each axis?
Rafael
The text was updated successfully, but these errors were encountered: