Export to Excel - url from hidden column..

Export to Excel - url from hidden column..

timcadieuxtimcadieux Posts: 76Questions: 22Answers: 0

Unfortunately I was never able to figure out how to use this example on the http://live.datatables.net page but here goes

I populate the table with text and a URL. I create a Font Awesome Link to the document in question using the below code but hide the column with the actual link from display.

When I export the column, it's blank...any suggestions on how to either export the Document Title hyperlinked or at worst, the url in its own column?

            var selector = "#datatable", table;
            if ($.fn.DataTable.isDataTable(selector)) {
                table = $(selector).DataTable();
                new $.fn.dataTable.Buttons(table, {
                    buttons: [
                       {
                           extend: 'excel',
                           title: GetExcelFileName(),
                           exportOptions: {
                               columns: [2, 1, 4, 0]
                           },
                           customize: function (xlsx) {
                               var sheet = xlsx.xl.worksheets['sheet1.xml'];
                               var col = $('col', sheet);
                               $(col[2]).attr('width', 50);
                           }
                       },
                       {
                           extend: 'pdf',
                           title: 'Export',
                           exportOptions: {
                               columns: [2, 1, 4, 0]
                           }
                       }
                    ]
                });
                table.buttons().container().prependTo($("#datatable-buttons"));

                $(".buttons-pdf").addClass("btn btn-md btn-default margin-left10");
                $(".buttons-excel").addClass("btn btn-md btn-default");
                //$(".buttons-wordCloud").addClass("btn btn-md btn-default margin-left10");
            }   

function UpdateData() {
    var $table = $("#datatable"),
      link

    //Return Query

    link = BuildQuery();

    $table.attr("class", "table table-hover table-stripped wb-tables");
    $table.attr(
        "data-wb-tables",
        '{"destroy": true, ' +
        '"bDeferRender": true, ' +
        '"language": {"processing": "Procesing...", "loadingRecords": "<img src =\'/../assets/images/loadingGif.gif\' alt=\'Loading...\'>"},' +
        '"order": [2, "desc"], ' +
        '"ajax": {"url": "' +
            link +
        '",  ' +
        '"dataSrc": "articles"}, ' +
        '"columns": [ ' +
        '{ "data": "articleUrl", "sTitle" : "' + linklabel + '", "width": "5%"},' +
        '{ "data": "title", "sTitle" : "' + titlelabel + '", "width": "40%" },' +
        '{ "data": "publicationDateInUsersTimeZone", "sTitle" : "' + datelabel + '", "width": "20%"},' +
        '{ "data": "publication.name", "sTitle" : "' + sourcelabel + '", "width": "20%", "orderable": false },' +
        '{ "data": "body", "sTitle" : "' + articlelabel + '", "visible": false }' +
        ']}');

    return "query";
}

$(document).on("xhr.dt", ".wb-tables", function (e, settings, json, xhr) {

    //Clean the Data
    if (json != null) {
        var data = json.articles;

        $.each(data, function (index) {
            // Link to Original URL
            this.articleUrl = '<a href=\"' + this.articleUrl + '\" target=\"_blank\"><i class=\"fa fa-external-link\"></i></a>';
        });

        json.articles = data;
    }

});
This discussion has been closed.