Cant extent custom button on table

Cant extent custom button on table

uTrxuTrx Posts: 24Questions: 6Answers: 0

I am trying to add some custom on datatables like select all and sedelect all. And to make export function to export only rows i have selected, i know i have done this with datatables normal script, but now is not working with this script. Any help?

$(function () {
    let dtButtons = $.extend(true, [], $.fn.dataTable.defaults.buttons)

    $.extend(true, $.fn.dataTable.defaults, {
        order: [[ 1, 'desc' ]],
        pageLength: 100,
        
        "columnDefs": [
            {
            orderable: false,
            className: 'select-checkbox',
            targets: 0
            },
        ],
        select: {
            style: 'multi', // multi checkbox
            selector: 'td:first-child'
        },

        dom: 'R<"clear">Blfrtip', 
        colReorder: true,
        "oColReorder": {
            "bAddFixed":false
        },

        buttons: [ 
            
            {
                extend: 'selectAll',
                className: 'btn btn-primary rounded mx-2'
            },
            {
                extend: 'selectNone',
                className: 'btn btn-secondary rounded mx-2'
            },
            {
                extend: 'copyHtml5',
                className: 'btn btn-info rounded mx-2',
                exportOptions: {
                    columns: [ 0, ':visible' ],
                    modifier: { search: 'none', selected: true}
                }
            },
            {
                extend: 'excelHtml5',
                className: 'btn btn-success rounded mx-2',
                exportOptions: {
                    columns: [ 0, ':visible' ],
                    modifier: { search: 'none', selected: true}
                }
            },
            {
                extend: 'csvHtml5',
                className: 'btn btn-danger rounded mx-2',
                exportOptions: {
                    columns: [ 0, ':visible' ],
                    modifier: { search: 'none', selected: true}
                }
            },
            {
                extend: 'pdfHtml5',
                className: 'btn btn-warning rounded mx-2',
                exportOptions: {
                    columns: [ 0, ':visible' ],
                    modifier: { search: 'none', selected: true}
                }
            },
            {
                extend: 'colvis',
                className: 'btn btn-light rounded mx-2'
            }
        ],

    });
    
    $('.datatable-User:not(.ajaxTable)').DataTable({ buttons: dtButtons })
    $('a[data-toggle="tab"]').on('shown.bs.tab', function(e){
        $($.fn.dataTable.tables(true)).DataTable()
            .columns.adjust();
    });
  
})

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    it would be worth looking at the Select extension, as that does those things,

    Colin

Sign In or Register to comment.