Export to Excel and PDF, a particular column is always blank
Export to Excel and PDF, a particular column is always blank
timcadieux
Posts: 76Questions: 22Answers: 0
I am using the export to Excel buttons. they work great except that I have a particular column, a URL column that always export blank.
Columns 0, 1, 4 print just fine but column 2 is always blank??
My json looks like this
{
"count": 42,
"articles": [
{
"id": "203999092",
"title": "Title goes here",
"body": "the Body goes here",
"categories": [ ],
"publication": {
"id": 213,
"name": "BBC News"
},
"publicationDate": "2017-01-03T15:54:18Z",
"creationDate": "2017-01-03T16:35:06.747Z",
"articleUrl": "http://www.infomedia.gc.ca/forces/2017/1/3/203999092"
},
I build the table
link = BuildQuery();
$table.attr("class", "table table-hover table-stripped wb-tables");
$table.attr(
"data-wb-tables",
'{"destroy": true, ' +
'"bDeferRender": true, ' +
'"order": [1, "desc"], ' +
'"ajax": {"url": "' +
link +
'", ' +
'"dataSrc": "articles"}, ' +
'"columns": [ ' +
'{ "data": "title", "sTitle" : "Title", "width": "60%" },' +
'{ "data": "publicationDateInUsersTimeZone", "sTitle" : "Published" },' +
'{ "data": "articleUrl", "sTitle" : "Url", "width": "5%", "orderable": false },' +
'{ "data": "publication.name", "sTitle" : "Details", "width": "5%", "orderable": false },' +
'{ "data": "body", "sTitle" : "Body", "visible": false }' +
']}');
I use this code to initialize the buttons
wb.doc.on("wb-ready.wb-tables", function () {
Modernizr.load({
load: [
"https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons" + wb.getMode() + ".js",
"https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5" + wb.getMode() + ".js",
"https://cdn.datatables.net/buttons/1.2.2/js/buttons.flash" + wb.getMode() + ".js",
"https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip" + wb.getMode() + ".js",
"https://cdn.rawgit.com/bpampuch/pdfmake/0.1.24/build/pdfmake" + wb.getMode() + ".js",
"https://cdn.rawgit.com/bpampuch/pdfmake/0.1.24/build/vfs_fonts" + ".js"
],
complete: function () {
var selector = "#datatable", table;
if ($.fn.DataTable.isDataTable(selector)) {
table = $(selector).DataTable();
new $.fn.dataTable.Buttons(table, {
buttons: [
{
extend: 'excel',
title: 'Export',
exportOptions: {
columns: [0, 1, 4, 2]
}
},
{
extend: 'pdf',
title: 'Export',
exportOptions: {
columns: [0, 1, 4, 2]
}
}
]
});
table.buttons().container().prependTo($("#datatable-buttons"));
$(".buttons-pdf").addClass("btn btn-md btn-default margin-left10");
$(".buttons-excel").addClass("btn btn-md btn-default");
}
}
});
});
This discussion has been closed.