row().child show on load

row().child show on load

Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

This is probably quite simple, however I cannot get it to work. I want my child rows to show by default when the table loads. I am using the following function to control the display of the child when an icon is clicked on the appropriate row:

    $('#cms_module_uptime_monitors tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = table.row( tr ); 
        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child( format(row.data()) ).show();
            tr.addClass('shown');
        }
    });

However, I would like the default state to be open and not closed.

Is this possible? I have manually tried to add the class 'shown' but it doesn't look like datatables has loaded the information yet, I guess that happens when the button is clicked?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Two options:

    1. Trigger the click event you've already got set up
    2. Call the row().child().show() method after the initialisation

    For 1, all you would do is:

    $('#cms_module_uptime_monitors tbody td.details-control').click();
    

    Allan

  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

    Thanks

This discussion has been closed.