TableExport icon indicating copy to clipboard operation
TableExport copied to clipboard

Loop through a nested table

Open harryadel opened this issue 5 years ago • 3 comments

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 avatar Oct 28 '18 18:10 harryadel

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

harryadel avatar Nov 04 '18 19:11 harryadel

Hi,

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

Expecting immediate response.

umamahesh0596 avatar Mar 01 '19 10:03 umamahesh0596

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!

harryadel avatar Mar 01 '19 11:03 harryadel