DataTable export SVG
DataTable export SVG
warningx06
Posts: 4Questions: 3Answers: 0
hello everyone. I am generating barcodes in SVG format with JsBarcode. When I try to export the barcodes I created later, such as excel, pdf, print, the barcode part appears blank. But I want the direct barcode to be exported as it was created. How can I do it? Thank you.
table = $("#example1").DataTable({
data: dataTable,
columns: [
{ title: "Barkod", data: "barkod", orderable: true },
],
columnDefs: [
{
targets: 0, // Barkod sütununun hedef indeksi (sıfırdan başlayarak)
render: function (data, type, row, meta) {
if (type === "display") {
var svgElement = `<svg class="barcode-container" barkod-index=${barcodeCounter} id="barcode${barcodeCounter}" data-barkod=${data}></svg>`;
barcodeCounter += 1;
return svgElement;
}
return data;
},
},
{ className: "dt-center", targets: "_all" },
],
searching: true,
responsive: true,
lengthChange: false,
pageLength: 15,
// buttons: ["copy", "csv", "excel", "pdf", "print", "colvis"],
dom: 'Bfrtip',
buttons: [
{
extend: "excel",
exportOptions: {
stripHtml: false,
columns: [0, 1, 2, 3, 4, 5, 6, 7],
},
},
{
extend: "copy",
},
{
extend: "csv",
},
{
extend: "pdf",
},
{
extend: "print",
},
{
extend: "colvis",
},
],
drawCallback: function () {
$(".barcode-container").each(function (index, element) {
updateBarcode(
element.getAttribute("id").replace("barcode", ""),
element.getAttribute("data-barkod")
);
});
},
});
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
I'm not familiar with JsBarcode I'm afraid, but if you can return the SVG for the renderer rather than in
drawCallback
then we could at least get the print view working (which in turn would allow a save as PDF in the browser). Is that possible?The Excel export is a whole different ballgame since you'd need to generate an image, save that in the Excel zip and reference them in the XML. Possible, but not something that our export attempts to do.
Allan
I see. Thank you. I will try.