How to set child rows

How to set child rows

haraldharald Posts: 16Questions: 7Answers: 1

I am trying to add several rows as child rows below a specific row. I am using the index to find the parent row. But I am only able to add the rows to the last position of the table but not as child rows of a specific row. Would be happy for some help. Thanks!

// my data
let tableData= {
        data: [
            {
               data1: 1,
               data2: 2,
               data3: 3,
               data4: 4
            },
            {
               data1: 1.1,
               data2: 2.1,
               data3: 3.1,
               data4: 4.1
            },
            etc....
        ],
        columns: [
            { title: 'row_1', data: 'data1'},
            { title: 'row_2', data: 'data2' },
            { title: 'row_3', data: 'data3' },
            { title: 'row_4', data: 'data4' }
        ]
    }

// filling the table
$('#testTable').DataTable(tableData);

Clicking on any row, the row data is sent to the server including the index of the row

// my response Data -> new child rows:
let responseData = [
                {
                   data1: child1,
                   data2: child1,
                   data3: child1,
                   data4: child1
                },
                {
                   data1: child2,
                   data2: child2,
                   data3: child2,
                   data4: child2
                },
                etc....
            ];

Setting the rows of the response data to the end of the table works:

let table= $('#testTable').DataTable();
table.rows.add(responseData).draw();

BUT HOW IS IT POSSIBLE TO SET CHILD ROWS VIA AN INDEX:

Something like:

    let table= $('#testTable').DataTable();
    let row = table.row( indexRow );
    row.child(rows.add(responseData)).show();

Answers

Sign In or Register to comment.