How to get Id value by clicking Edit button on the same row of DataTable

后端 未结 4 424
滥情空心
滥情空心 2021-01-15 08:32

I use jQuery Datatable for listing records and add an Action button (Edit) for editing the record on a modal dialog. If I select a row I can get th

4条回答
  •  深忆病人
    2021-01-15 09:27

    You can use this code to achieve this.

    var table;
    $(document).ready( function () {
     table  = $('#example').DataTable();
    } );
    
    $('body').on('click', '#btnEdit', function(){
        //to get currently clicked row object
        var row  = $(this).parents('tr')[0];
    
        //for row data
        console.log( table.row( row ).data() );
    
    });
    

    It will return row data as a string array.

    Live Demo Here

    Use the browser console to see the results.

提交回复
热议问题