Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82536

Adding child rows without toggle sign

$
0
0

I want to dynamically add child rows below each parent rows in HTML table. This link shows how to do it by adding hide/show option:- https://datatables.net/examples/api/row_details.html, but I want to avoid that and display child rows without having to click show/hide option. Also the data are dynamically loaded from ajax call. I parse the JSON response from ajax call and append in HTML table using JavaScript and DataTable in following way:-

function displayFruits() {

$.ajax({

    type: "GET",
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    dataType: "json",
    url: "http://www.dummyexample.com",

    success: function(data) {

            tr = $('<tr/>');
            tr.append("<td>" + data[i].name + "</td>");
            tr.append("<td>" + data[i].type + "</td>");
            tr.append("<td>" + data[i].cost + "</td>");
            tr.append("<td>" + data[i].season + "</td>");
            tr.append("<td>" + data[i].vitaminContent + "</td>");
            $('#tableId').append(tr);
        }

            $('#tableId').DataTable();
    },
    error: function(xhr, ajaxOptions, thrownError) {
        // handle your fail response here
}); //end of ajax

} // end of displayFruits() function

In above example, instead of displaying season and vitaminContent in separate column, I want to display them as child row below parent row. How can I achieve that?


Viewing all articles
Browse latest Browse all 82536

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>