Skip to content Skip to sidebar Skip to footer

Datatables - Export Values Inside And Outside The Field Input And Value Of The Select Field

let's see who can help me solve this problem. I have several tables with the JS datatables plugin (https://datatables.net/) My problem is in exporting the data in PDF and Excel. I

Solution 1:

I've been struggling with this one recently and finally found the solution. I'll try to make it a bit more detailed.

Here's a function that checks if the exported node is the node. In such case it returns the input.value - otherwise just the data:

//function for DataTable data export to export <input>.valuevar buttonCommon = {
    exportOptions: {
        format: {
            body: function ( data, row, column, node ) {
                //check if type is input using jqueryreturn node.firstChild.tagName === "INPUT" ?
                        node.firstElementChild.value :
                        data;

            }
        }
    }
};

Now, with this function defined, we use it to extend the buttons:

buttons: [
        $.extend( true, {}, buttonCommon, {
            extend: 'copyHtml5'
        } ),
        $.extend( true, {}, buttonCommon, {
            extend: 'excelHtml5'
        } ),
        $.extend( true, {}, buttonCommon, {
            extend: 'pdfHtml5'
        } ),
        $.extend( true, {}, buttonCommon, {
            extend: 'csvHtml5'
        } )
        ],

Solution 2:

var buttonCommon = {
    exportOptions: {
        format: {
            body: function(data, column, row, node) {
                if (row == 1) {
                    return $(data).is("div") ? $(data).text() : data
                }
                elseif (row == 4) {
                    return $(data).is("select") ? $(data).val() : data
                }
                else {
                    return $(data).is("input") ? $(data).val() : data
                }
            }
        }
    }
};
$(document).ready(function() {
    $('#tables').DataTable({
        dom: 'Bfrtip',
        "paging": !1,
        buttons: [$.extend(!0, {}, buttonCommon, {
            extend: "excel"
        })]
    })
});

Solution 3:

ok, in your button

                        exportOptions: {
                        orthogonal: 'export',
                    }

in your columns :

            render: function (data, type, row) {
            returntype === 'export' ? row.Descripcion: "";
        }

Post a Comment for "Datatables - Export Values Inside And Outside The Field Input And Value Of The Select Field"