Child row vs colvis

Child row vs colvis

nwickinwicki Posts: 20Questions: 8Answers: 0

I am using the 'colvis' button in my setup in combination with child rows.

I got the ideas on how to do that from and

I built a showcase for my problem on

If you click on the "closed" cell, a child row should open up. By clicking on it again it should disappear. Now, if you were to use the "Column Visibility" button on top of the table, and click on a name of a column the column disappears where the content resides beside the table which does not happen if the child row was not activated during the session.

Does anyone know how to solve this problem?

This question has an accepted answers - jump to answer


  • nwickinwicki Posts: 20Questions: 8Answers: 0

    A little update to my previous problem. It still persists, but a second problem occurs if you remove columns with the "colvis" button from the beginning of the table after having invoked the child rows.

    So, if you activate the first child row, then remove the column "name" and immediately try to add it, we get the following exception:
    Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.

    I assume this is related to the previous problem stated and hope I can find a solution which solves both.

  • kthorngrenkthorngren Posts: 8,082Questions: 25Answers: 1,816
    Answer ✓

    Seems the problem is the result of this statement:
    tr[0].innerHTML = tr[0].innerHTML.replace('open', 'closed');

    Commenting it out seems to resolve the issue. I updated the test case to use cell().data() to update the column with open/closed. Note I also changed the default column being sorted so the update doesn't affect sorting.


  • nwickinwicki Posts: 20Questions: 8Answers: 0

    Hmm, I appreciate your effort. But I do not know what test case you are talking about. I cannot see any difference in . Also, when using cell().data() I get the data inside the child row and no possibility to update the contents of the header row. Am I missing anything?

  • nwickinwicki Posts: 20Questions: 8Answers: 0

    Oh, I am sorry. I again tried it with your approach and it seems I messed it up before. It works now. Thank you very much.

  • nwickinwicki Posts: 20Questions: 8Answers: 0

    I now finished implementing it. Since I couldn't post the original code, I made some mistakes in the showcase which is why the answer was correct for the showcase, but not for the actual case I am using.
    Nonetheless, the answer helped me find the bug and how to solve it which is why I am posting an adjusted showcase below which more accurately resembles the actual code I am working on and hopefully can help someone.

    <!DOCTYPE html>
        <script src=""></script>
        <script src="//" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="//">
            .closed-class::before {
                content: "closed";
            .open-class::before {
                content: "open";
            $(document).ready(function () {
                var table = $('#example').DataTable({
                    dom: 'Bfrtip',
                    buttons: ['colvis']
                $('#example tbody').on('click', 'td.details-control', function () {
                    var tr = $(this).closest('tr');
                    var row = table.row(tr);
                    if (row.child.isShown()) {
                        var iconNode = row.node().childNodes[1];
                    else {
                        var iconNode = row.node().childNodes[1];
            function format(row) {
                var div = $('<div />')
                    .html('Example text.');
                return div;
        <table id="example" class="display" style="width:100%">
                    <td class="details-control"></td>
                    <th>Start date</th>
                    <td class="details-control closed-class"></td>
                    <td>Tiger Nixon</td>
                    <td>System Architect</td>
                    <td class="details-control closed-class"></td>
                    <td>Garrett Winters</td>
                    <td class="details-control closed-class"></td>
                    <td>Ashton Cox</td>
                    <td>Junior Technical Author</td>
                    <td>San Francisco</td>
Sign In or Register to comment.