Some way to add html row

Some way to add html row

xGs_MancoxGs_Manco Posts: 9Questions: 2Answers: 0

exists any way to add a row with a html ???
i know that if i want to add i need pass a array parameter.
But if i have the html row?

i want to do this

table.row.add("<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>");

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,332Questions: 26Answers: 4,774
    Answer ✓

    The following should work:

    table.row.add($("<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>")).draw();
    

    jQuery converts it to nodes for Datatables.

    Kevin

  • xGs_MancoxGs_Manco Posts: 9Questions: 2Answers: 0
    edited February 2018

    Hello!! @kthorngren
    It worked!!!! But now i have another problem ...

    When it was added to the table, another group was created.

    I'm using this code to create a group.

    "drawCallback": function (settings) {
                var api = this.api();
                var rows = api.rows({ page: 'current' }).nodes();
                var last = null;
                var cantidadColumnasVisibles = $(api.columns().header()).filter(':visible').length;
    
                api.column(0, { page: 'current' }).data().each(function (group, i) {
                    if (last !== group) {
                        $(rows).eq(i).before(
                            '<tr><td colspan="4">group name</td></tr>'
                        );
                        last = group;
                    }
                });
    
  • kthorngrenkthorngren Posts: 20,332Questions: 26Answers: 4,774

    That's interesting code. Are you trying to do something like the Row Group extension?

    Without more context around what your data and groups are I'm not sure I understand how to help.

    Kevin

This discussion has been closed.