Rowgroup sum and total

Rowgroup sum and total

kingjia90kingjia90 Posts: 1Questions: 0Answers: 0
edited May 2014 in DataTables 1.10

Hi,

I wanted to share the code that i made to use rowgroup plugin to get total and subtotal of each subgroup
http://jsfiddle.net/X5LB9/

Hope will help someone, and if there are some part of code that can be improved, i'll be glad to learn from that.

One note: if i enable stateSave, the default rowgroup (clicking on gray one, or ordering by column 0), get's messed up. Any guess?

J

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Thanks for sharing this with. Regarding your question, you might want to ask in the rowGrouping plug-ins issue list. it isn't supported as part of the DataTables project as it is third party software.

    Allan

  • MikeSMikeS Posts: 113Questions: 1Answers: 0

    I don't think that he is using the row grouping plugin for this. From what I can determine (and maybe I'm wrong), his shared code is just a modified version of your row grouping code taken from the Advanced Initialization Examples.

    BTW, I would be grateful if the author of the row grouping plugin could make it work with dataTables version 1.10. too.

  • redwallredwall Posts: 11Questions: 1Answers: 0

    I am too looking for sub totals on the groups as well as expand/collapse functionality.

    I am using the latest version of datatables and I can see it does support grouping, but not group totals or expand collapse.

    There is then a plugin which handles expand /collapse but not group totals. http://jquery-datatables-row-grouping.googlecode.com/svn/trunk/collapsibleGroups.html

    I would rather avoid using a plugin if we can get it working using datatbales itself.

    @allan, do you recommend using the plugin mentioned above to try and have grouping / sub-totals and expand collapse or will there be a solution soon built into DT?

    @kingjia90 - thanks a lot for the example on jsfiddle mate, really helps to see an example of the code..do you plan on doing expand / collapse in that example instead of clicking on the groups to resort?

    Cheers

  • redwallredwall Posts: 11Questions: 1Answers: 0

    Hi, I managed to figure out the expand / collapse on groups by adding this click event to the code

    // Collapse / Expand Click Groups
    $('.grid tbody').on( 'click', 'tr.group', function () {
    var rowsCollapse = $(this).nextUntil('.group');
    $(rowsCollapse).toggleClass('hidden');
    });

    where the hidden class is set to display 'none'...

    I updated a fiddle here for anyone looking to do the same http://jsfiddle.net/X5LB9/1/

    The remaining problem I have is that TableTools does not export the group headers. Has anyone got that working?

  • MikeSMikeS Posts: 113Questions: 1Answers: 0

    @redwall, thanks for sharing that modified fiddle to allow expand/collapse of the groups. One thing that I've noticed is that if you sort on any column, the groups are all rearranged (unlike the rowGrouping plugin behavior which I prefer). Furthermore, there is no way to get back the original row groups except by refreshing the page.

  • mann123mann123 Posts: 1Questions: 0Answers: 0

    You're genius. THANK YOU SO MUCH for the fiddle.

  • Katrina_EngelbrechtKatrina_Engelbrecht Posts: 3Questions: 0Answers: 0

    @redwall, thank you very much that you share such an useful example for the people in the world!;)

This discussion has been closed.