tablesorter icon indicating copy to clipboard operation
tablesorter copied to clipboard

Unable to download table as excel.

Open rdasgupta7141 opened this issue 3 years ago • 7 comments

Here is my code but it does not seem to download anything. Also advise how to download as an excel with the column header and filtered subset on the table.

I followed the https://github.com/Mottie/tablesorter/issues/963

Is there a specific version I need to be using?

$(function () {
    var $table = $('table');

    $('#exportGrid').click(function () {
        $table.trigger('outputTable');
    });

    $table.tablesorter({
        theme: 'blue',
        widgets: ['zebra', 'output'],
        widgetOptions: {
            output_delivery: 'd',
            output_separator: ';'
        }
    });
})

rdasgupta7141 avatar May 25 '21 19:05 rdasgupta7141

Hi @rdasgupta7141!

No specific version. Please follow the examples in the issue that you shared. You'll need to include the output_callback function along with one of the excel JS library to export an excel directly. Or just download the table as a CSV and import it into excel.

Mottie avatar May 25 '21 23:05 Mottie

Thanks @Mottie for your response. I don't see anything happening when I click on the download button. I followed along that example.

$(function () {
    var $table = $('table');

    $('#exportGrid').click(function () {
        $table.trigger('outputTable');
    });
    $('table').tablesorter({
        theme: 'blue',
        widgets: ['zebra', 'filter', 'output'],
        widgetOptions: {
            output_separator: 'array',
            output_saveFileName: 'test.xlsx',
            output_callback: function (config, data) {
                // data is set to be an array of arrays
                var wbout,
                    wo = config.widgetOptions,
                    ws_name = "SheetJS",
                    wb = new Workbook(),
                    ws = sheet_from_array_of_arrays(data);
                /* add worksheet to workbook */
                wb.SheetNames.push(ws_name);
                wb.Sheets[ws_name] = ws;
                wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'binary' });

                saveAs(new Blob([s2ab(wbout)], { type: "application/octet-stream" }), wo.output_saveFileName);

                // stop further output widget processing
                return false;
            }
        }
    });
})

rdasgupta7141 avatar May 26 '21 00:05 rdasgupta7141

    <button id="exportGrid" type="button" class="btn btn-sm btn-success" >
                    <i class="glyphicon glyphicon-save"></i>
                    Excel File
    </button>
 <div class="table-responsive">
            <table class="tablesorter table table-bordered table-striped table-hover table-condensed">
                <thead>
                 </thead>
                <tbody>                 
                </tbody>
            </table>

rdasgupta7141 avatar May 26 '21 00:05 rdasgupta7141

<div class="table-responsive">
            <table class="tablesorter table table-bordered table-striped table-hover table-condensed">
                <thead>
                    <tr>
                        <th>

rdasgupta7141 avatar May 26 '21 00:05 rdasgupta7141

Did you include the js-xlsx library? https://github.com/SheetJS/sheetjs#installation

Mottie avatar May 26 '21 13:05 Mottie

I did download xlsx.core.min.js and added to the layout.cshtml.

How may I even have it download as a csv? I don't see anything happening after the code executes the following line. $table.trigger('outputTable');

rdasgupta7141 avatar May 26 '21 15:05 rdasgupta7141

I might not be including all the .js files right for tablesorter. So I added the following in my layout.cshtml

wwwroot/lib/jquery.tablesorter/js/jquery.tablesorter.js, wwwroot/lib/jquery.tablesorter/js/extras/jquery.tablesorter.pager.min.js lib/jquery.tablesorter/js/widgets/widget-output.min.js I am pretty sure I am missing something. Please let me know what I may be doing wrong.

rdasgupta7141 avatar Jun 01 '21 22:06 rdasgupta7141