Multiple tables - How to add a row

Multiple tables - How to add a row

poldo93poldo93 Posts: 5Questions: 2Answers: 0

Good morning,
I'm working on multiple datatables created in one page, initialized by $('table.display').DataTable({opts})
How is it possible to add a row in one of the tables, supposing that each table has its own "add button"?

Thank you,
Paolo.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @poldo93 ,

    You can either use jQuery selectors to access the tables independently still, or use the return from the initialisation. Hope this example helps - the page length is changed using both of those methods.

    Cheers,

    Colin

  • poldo93poldo93 Posts: 5Questions: 2Answers: 0

    Thank you for the quick reply Colin!

    I tried this solution: tables.table(1).row().add().draw( false );
    An error message appear: "Cannot read property "nodename" of undefined"

  • colincolin Posts: 15,143Questions: 1Answers: 2,586
    Answer ✓

    Hi @poldo93 ,

    I'm guessing it's because you're not passing in the row to add. It should be:

    tables.table(1).row.add(ROWDATA).draw( false );
    

    ROWDATA would either be an array or an object, depending upon your data - see here.

    Cheers,

    Colin

  • poldo93poldo93 Posts: 5Questions: 2Answers: 0

    I thought that was possible insert an empty row, that was my error!

    Many thanks again Colin!

This discussion has been closed.