Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Loop through a nested table #152

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

harryadel
Copy link

@harryadel harryadel commented Oct 28, 2018

Hello there,
we had this three nested tables within a big table where we provided data for it using datatable, now when we download it, all table headers would be listed consecutively underneath each other followed by the rows of each table in order.

<table class="col-md-12" id="tablesContainer"> 
        <div class="loader" style="margin:0 auto;" hidden></div>
        <table class="panel panel-visible table table-hover report-table table-bordered display" id="constHighLights-0" style="width:100%">
        </table>
        <table class="panel panel-visible table table-hover report-table table-bordered display" id="constHighLights-1" style="width:100%">
        </table>
        <table class="panel panel-visible table table-hover report-table table-bordered display" id="constHighLights-2" style="width:100%">
        </table>
      </table>
// It'd look like so
name age add
name age add
name age add
Clark x x
Mark x x
Park x x

So, digging into your package we found a little workaround and decided to create a merge request for it

var context = {};

            var _setContextRows = function (element) {
                var container = {};
                container.rows = _nodesArray(element.querySelectorAll('tbody > tr'));
                container.rows = settings.headers ? _nodesArray(element.querySelectorAll('thead > tr')).concat(container.rows) : container.rows;
                container.rows = settings.footers ? container.rows.concat(_nodesArray(element.querySelectorAll('tfoot > tr'))) : container.rows;
                container.thAdj = settings.headers ? element.querySelectorAll('thead > tr').length : 0;
                return container
            }
            context.rows = [];
            context.thAdj = 0;
            function recurse(element) {
                var wrapperElement = element || el;
                if (wrapperElement.querySelectorAll('table').length) {
                    wrapperElement.querySelectorAll('table').forEach((value, index) => {
                        recurse(value);
                    });
                } else {
                    Array.prototype.push.apply(context.rows, _setContextRows(wrapperElement).rows);
                    context.thAdj += _setContextRows(wrapperElement).thAdj;
                }
            }

            recurse();
    
                context.filename = settings.filename === 'id'
                    ? (el.getAttribute('id') ? el.getAttribute('id') : self.defaultFilename)
                    : (settings.filename ? settings.filename : self.defaultFilename);
                context.uuid = _uuid(el);
    

It has got some jagged edges that needs to be smoothed out, so we're definitely open for feedback/edits.

EDIT: Another commit has been added to fix CI, so it's better to squash into single commit.

@harryadel
Copy link
Author

@clarketm Hi, I hope you can checkout my PR, thanks!

@umamahesh0596
Copy link

Hi,

I also have multiple tables inside main table. Request your support to exclude inside tables in the excel.

Expecting immediate response.

@harryadel
Copy link
Author

Request your support to exclude inside tables in the excel.

Uhh, could you please elaborate on what you mean by that? I don't get you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants