Using 1.10.21 and buttons.html5 v 1.3.3 all my & characters are exporting as &

Using 1.10.21 and buttons.html5 v 1.3.3 all my & characters are exporting as &

mahone10mahone10 Posts: 1Questions: 1Answers: 0
edited March 2022 in Buttons

When exporting to Excel all & characters showing up as &

     table = $('#requestTbl').DataTable(
                {
                    //"sDom": "<'row mt-1'<'col-md-12 col-sm-12 p-0'>B>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-md-4 col-sm-12'l><'col-md-4 col-sm-12 text-center'i><'col-md-4 col-sm-12 text-center'p>>",
                    "sDom": "<'row mt-1'<'col-md-6 col-sm-12'f><'col-md-6 col-sm-12'B>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-md-4 col-sm-12'l><'col-md-4 col-sm-12 text-center'i><'col-md-4 col-sm-12 text-center'p>>",
                    "language": {
                        "paginate": {
                            "previous": "Prev",
                            "next": "Next"
                        },
                        "info": "_START_ to _END_ of _TOTAL_",
                        "infoEmpty": "No entries",
                        "infoFiltered": "(filtered from _MAX_)",
                    },
                    "pagingType": "full",
                    "searchable": false,
                    "pageLength": 5,
                    "lengthMenu": [5, 10, 20, 50, 100, 200, 500],
                    "columnDefs": [
                        { targets: [8, 9, 10, 11, 12], orderable: false },
                        { targets: [10, 11], visible: false }
                    ],
                    "select": false,
                    "orderCellsTop": true,
                    buttons: [
                        {
                            extend: 'excelHtml5',
                            exportOptions: {
                                columns: 'th.exportable',
                                stripHtml: false,   //have tried with and without
                                decodeEntities: true,  //have tried with and without
format: {
                                    header: function (data, row, column, node) {
                                        var l = data.indexOf('<');
                                        data = data.substr(0, l == -1 ? data.length : l);
                                        return data;
                                    },
                                    body: function (data, row, column, node) {
                                        if (column === 9) {
                                            var startIndex = data.indexOf('<li>');
                                            var returnData = "";
                                            while (startIndex != -1) {
                                                var endIndex = data.indexOf("</li>");
                                                returnData += data.substring(startIndex + 4, endIndex)
                                                data = data.substr(endIndex + 4);
                                                startIndex = data.indexOf('<li>');
                                                if (startIndex != -1)
                                                    returnData += ',';
                                            }

                                            return returnData;
                                        } else if (column === 8) {
                                            return '\u200C' + data;
                                        } else if (column >= 12) {
                                            var startIndex = data.indexOf('<a');
                                            var returnData = data.substring(0, startIndex).trim();
                                            return returnData;
                                        }
                                        return data;

                                    }
                                }
                            }

                        }
                    ],
                    "order": [[0, "asc"]],
                    initComplete: function () {
                        $('.dt-buttons a').addClass('btn btn-primary float-right mr-1 my-2');
                        $('.dt-button').removeClass('dt-button');
                        $(".dt-buttons a:contains('Excel')").append("<i class='ml-1 fas fa-file-excel'></i>")

                        this.api().columns().every(function () {

                            var column = this;
                            if (column.index() == 0 || column.index() == 5 || column.index() == 7) {
                                var uList = $("<div id='requestTblSelect" + column.index() + "' class='dropdown-menu scroll-sm'><a class='dropdown-item' href='#' onclick=\"applyFilter('requestTbl'," + column.index() + ",'',0);  return false;\">No Filter</a></div>");
                                var select = $("<div class='btn-group d-block'><button type='button' class='btn btn-light border border-dark dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'><span id='requestTbllabel" + column.index() + "'>No Filter</span></button></div>")
                                select.append(uList);
                                select.appendTo($('#requestTblHdr' + column.index()));

                                column.data().unique().sort().each(function (d, j) {
                                    uList.append("<a class='dropdown-item' href='#' onclick=\"applyFilter('requestTbl'," + column.index() + ",'" + escapeString(d, false) + "',0); return false;\">" + d + "</a>");
                                });
                            } else if (column.index() == 1) {
                                var uList = $("<div id='requestTblSelect" + column.index() + "' class='dropdown-menu scroll-sm'><a class='dropdown-item' href='#' onclick=\"applyFilter('requestTbl'," + column.index() + ",'',0);  return false;\">No Filter</a></div>");
                                var select = $("<div class='btn-group d-block'><button type='button' class='btn btn-light border border-dark dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'><span id='requestTbllabel" + column.index() + "'>No Filter</span></button></div>")
                                select.append(uList);
                                select.appendTo($('#requestTblHdr' + column.index()));

                                uList.append("<a class='dropdown-item' href='#' onclick=\"applyFilter('requestTbl'," + column.index() + ",'Closed',0); return false;\">Closed</a>");
                                uList.append("<a class='dropdown-item' href='#' onclick=\"applyFilter('requestTbl'," + column.index() + ",'Open',0); return false;\">Open</a>");
                                uList.append("<a class='dropdown-item' href='#' onclick=\"applyFilter('requestTbl'," + column.index() + ",'Pending',0); return false;\">Pending</a>");

                            }

                        });
                        applyFilter('requestTbl', 1, 'Open', 0);
                    }
                });

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.