Error when add new row

Error when add new row

seraviferseravifer Posts: 5Questions: 2Answers: 0

After many lines of code print the new row:
var Row = $(".contact").append("<tr id='""'><td class='nombre'></td><td class='categoria'></td><td class='movil'></td><td class='empresa'></td><td><a href='#' id='""' class='del'>Eliminar</a> <a href='#' id='""' class='edit'>Editar</a></td></tr>");
*I tried without "tr".

And then add the row to my table defined:
table.row.add(Row).draw();

And show this error: Uncaught TypeError: Cannot read property 'nodeName' of undefined

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,772Questions: 1Answers: 10,511 Site admin

    In the above code you are passing the .contact elements into the row.add() method. Is that really what you want? Why not just pass in the tr HTML or element?

    Allan

  • seraviferseravifer Posts: 5Questions: 2Answers: 0

    Sorry, but I do not understand what you mean. I add a new row to the table. My problem is that DataTables not recognize the new row so if I try to interact with it removed.

  • allanallan Posts: 63,772Questions: 1Answers: 10,511 Site admin

    Reading the code above you insert a tr element into all .contact elements on the page. You then add those .contact elements (I don't know if there is more than one) to the table.

    Why not just do:

    var Row = "<tr id='""'><td class='nombre'></td><td class='categoria'></td><td class='movil'></td><td class='empresa'></td><td><a href='#' id='""' class='del'>Eliminar</a> <a href='#' id='""' class='edit'>Editar</a></td></tr>";
    
    table.row.add(Row).draw();
    

    I don't understand why you would what to insert it into .contact first.

    Allan

  • seraviferseravifer Posts: 5Questions: 2Answers: 0
    edited March 2016

    OK understood. The ".contact" is the name of the table.
    I tried but it does not work well. Returns something strange screen. Pick up a character for each column.

    1 column <
    2 column t
    3 column r
    4 column
    5 column i ...

  • allanallan Posts: 63,772Questions: 1Answers: 10,511 Site admin
    edited March 2016 Answer ✓

    Can you link to the page showing the issue so I can debug it then please.

    edit The other thing you could try is table.row.add( $(Row) ).draw().

    Thanks,
    Allan

  • seraviferseravifer Posts: 5Questions: 2Answers: 0

    Perfect, it works. Thank you.
    The web is not online yet.

This discussion has been closed.