How i can combine load data ajax and use button print also in datatable

How i can combine load data ajax and use button print also in datatable

rulikrulik Posts: 1Questions: 1Answers: 0
edited June 2023 in Free community support
$(document).ready(function() {
        var printCounter = 0;
        var h3 = '<h3 align="center">';
        var h33 = '</h3>';
        var table = $('#tbltagihancustlog').DataTable({
            "responsive": true,
            "autoWidth": false,
            "width": "100%",
            buttons: [
                'copy',
                {
                    extend: 'excel',
                    messageTop: 'Laporan Tagihan Customer LOG Pada' + ' {{ date('M-Y') }}' + '',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'print',
                    title: h3 + 'Laporan Tagihan Customer LOG' + h33,
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                'colvis'
            ],
            ajax: {
                url: "{{ route('data-API') }}",
                type: "GET",
                dataType: "json",
                dataSrc: "tagihancustlogsales", 
            },
            columns: [{
                    data: null,
                    render: function(data, type, row, meta) {
                        return meta.row + 1;
                    }
                },
                {
                    data: "custname"
                },
            ]

        });
        table.on('draw', function() {
            table.buttons().container().appendTo('#tbltagihancustlog_wrapper .col-md-6:eq(0)');
        });
    });

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

Answers

  • allanallan Posts: 63,302Questions: 1Answers: 10,431 Site admin

    How i can combine load data ajax and use button print also in datatable

    Exactly as you have done. If that isn't working for you, please link to a test case showing the issue, as per the template text for a new post and as detailed in the forum rules.

    Allan

Sign In or Register to comment.