DataTables get data from render row parameter

DataTables get data from render row parameter

silvior92silvior92 Posts: 3Questions: 1Answers: 0

Hi everyone, I'm using DataTables pluging for Jquery, this is what I'm trying to do:

$('#familiars').DataTable({
    processing: true,
    serverSide: true,
    ajax: "/familiars/list/",
    columns: [
        { data: 'id' },
        { data: 'name' },
        { data: 'lastname' },
        { data: 'age' },
        { data: 'country'  },
        { data: 'address' },
        { data: 'id', render : function (data, type, row){                
            btn='<a class="btn btn-success" href="#" data-toggle="modal" data-target="#modal-edit" onclick="setRow( \'' +row+ '\' )"/><i class="fa fa-edit"></i> Edit</a>';               
        return btn;
            }
        },
    ],
});

function setRow(row){
    console.log(JSON.stringify(row));
    console.log(row);
    console.log(row.id);
    console.log(row.name);
}

Pass the row parameter through the function to get all the data from the row and use it to a edit form modal but in the function setRow I only get object Object in all that's trys

If I use for example row.name or data in the onclick="setRow( \'' +row+ '\' )"/ get the info but I want get all in the row parameter or another way to get all the row info to the function.

Thanks for the help!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 1,741Questions: 0Answers: 321
    Answer ✓

    Hi @silvior92 ,

    This example here (and this one) is similar to what you're doing, but the click is handle by jQuery. It would be trivial for you to change your button to have a click event similar to this. Is this something you could do?

    Cheers,

    Colin

  • silvior92silvior92 Posts: 3Questions: 1Answers: 0

    Thanks! I remove the onclick event and its working like this:

    $('#t_familiars tbody').on( 'click', 'tr', function () { 
        var data = t_familiars.row( this ).data() ; 
        alert(data['name']); 
    });
    
Sign In or Register to comment.