I have a question regarding customiation of datatable. I want to customized it.

I have a question regarding customiation of datatable. I want to customized it.

dayanahmed66dayanahmed66 Posts: 2Questions: 1Answers: 0
edited November 2020 in Free community support

After Clicking on the Print, PDF button I want to print a customized heading on the sheet(i.e. print or pdf sheet) : Kindly help me out with this
I have used this code for heading

   $(document).ready(function () {
                $('#expense_table').DataTable({
                    dom: 'Bfrtip',
                    header: 'This is heading',
                    buttons: [
                        'excel', 'pdf', 'print'
                    ]
                });
            }); 

Thanks.

Answers

  • kthorngrenkthorngren Posts: 20,145Questions: 26Answers: 4,736

    See if this example helps.

    Kevin

  • dayanahmed66dayanahmed66 Posts: 2Questions: 1Answers: 0
    edited November 2020

    I found this snippet helpful to me.

    $(document).ready(function () {
                $('#expense_table').DataTable({
                    dom: 'Bfrtip',
                    lengthChange: false,
                    buttons: [
        
                    {
                        extend: 'print',
                        title: '',
                        customize: function ( win ) {
                            $(win.document.body)
                                .css( 'font-size', '10pt' )
                                .prepend(
                                    '<h1 class="text-center text-primary">Headings</h1>'
                                )
        
         
                            $(win.document.body).find( 'table' )
                                .addClass( 'compact' )
                                .css( 'font-size', 'inherit' );
                        }
                    }
                ]
                });
            });
    
This discussion has been closed.