3

I'm using this code and it is working fine.

But I want to get limited row data and limited words from a row from datatable.

What I'm doing Jquery code:

if( $('.clienttable').length > 0 ) {
        $('.clienttable').DataTable( {           
            pageLength: 10,
            responsive: true,
            dom: '<"html5buttons"B>lTfgitp',
            buttons: [
                {
                    extend: 'copyHtml5',
                    exportOptions: {
                        columns: [1, 2, 3,4,5,6]
                    }
                },
                {
                    extend: 'csvHtml5',
                    exportOptions: {
                        columns: [1, 2, 3,4,5,6]
                    }
                },
                {
                    extend: 'excelHtml5',
                    exportOptions: {
                        columns: [1, 2, 3,4,5,6]
                    }
                },
                {
                    extend: 'pdfHtml5',
                    exportOptions: {
                        columns: [1, 2, 3,4,5,6]
                    },
                    title: 'List of Clients',
                }
            ],
            columnDefs: [
                { targets: [0], orderable: false },
                { targets: [7], orderable: false }
             ],
            "order": [[ 6, "desc" ]]  
        });
    }

Frontend Code:

<table class="table table-striped table-bordered table-hover clienttable" >
</table>

Other Question:

How to remove white spaces text in columns when excel export..? i m getting issues like white spaces in the excel table cell, can this be possible to remove white spaces..?

1 Answer 1

1

You can use DataTables Select extension: DataTables Select

Add to button export options:

modifier: {
      selected: true
}

and

select: true

to initialize DataTable code.

Your new code:

if( $('.clienttable').length > 0 ) {
    $('.clienttable').DataTable( {           
        pageLength: 10,
        select: true,
        responsive: true,
        dom: '<"html5buttons"B>lTfgitp',
        buttons: [
            {
                extend: 'copyHtml5',
                exportOptions: {
                    columns: [1,2,3,4,5,6],
                    modifier: {
                        selected: true
                    }
                }
            },
            {
                extend: 'csvHtml5',
                exportOptions: {
                    columns: [1,2,3,4,5,6],
                    modifier: {
                        selected: true
                    }
                }
            },
            {
                extend: 'excelHtml5',
                exportOptions: {
                    columns: [1,2,3,4,5,6],
                    modifier: {
                        selected: true
                    }
                }
            },
            {
                extend: 'pdfHtml5',
                exportOptions: {
                    columns: [1,2,3,4,5,6],
                    modifier: {
                        selected: true
                    }
                },
                title: 'List of Clients',
            }
        ],
        columnDefs: [
            { targets: [0], orderable: false },
            { targets: [7], orderable: false }
         ],
        "order": [[ 6, "desc" ]]  
    });
}

Now you can print only selected rows.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer... @Zafahix but is not working exactly what i want
@VishvakarmaDhiman So you need a function that prints, for example, the first 50 results?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.