How do I add button on each row in datatable?

前端 未结 7 1349
醉话见心
醉话见心 2020-11-30 23:54

I am newbie for DataTables. I want to add button on each row for edit and delete(like below image)

\"enter

7条回答
  •  我在风中等你
    2020-12-01 00:23

    take a look here... this was very helpfull to me https://datatables.net/examples/ajax/null_data_source.html

    $(document).ready(function() {
        var table = $('#example').DataTable( {
            "ajax": "data/arrays.txt",
            "columnDefs": [ {
            "targets": -1,
            "data": null,
            "defaultContent": ""
        } ]
    } );
    
    $('#example tbody').on( 'click', 'button', function () {
        var data = table.row( $(this).parents('tr') ).data();
        alert( data[0] +"'s salary is: "+ data[ 5 ] );
        } );
    } );
    

提交回复
热议问题