Add row and custom data

Add row and custom data

marcpiratmarcpirat Posts: 51Questions: 18Answers: 0

hi

I need to add row dynamicly to the datatable and after i will do a safe.

var specsTable = $('#specsTable').DataTable({
...
});

I can use row.add like

specsTable.row.add( [
$("#field1").val(),
$("#field2").val()
]);

I would to add some attribute (like data-id) for some field

Is there a way to do it?

thanks

This question has an accepted answers - jump to answer

Answers

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

    Hi @marcpirat ,

    You can use node() and to$() to get the node of the added row, something like this:

    specsTable.row.add( [ ... ] ).node().to$().attr( 'data-id', 'yourID');
    
    

    Cheers,

    Colin

This discussion has been closed.