Avatar of Wayne Atherton
Wayne Atherton
 asked on

Close the previous detailed view, Child Rows, JQuery DataTables

Hi there,

I want to create a Jquery datatable within the child row of the main datatable.

The detailed data table, is going to contain the same information, and using the standard examples on the DataTables site, I can achieve what i require by using the following code.

$("#messagesDT tbody").on("click", "td.details-control", function () {

        var tr = $(this).closest("tr");
        var row = oData.row(tr);

        if (row.child.isShown()) {
            
            $('div.slider', row.child()).slideUp(function () {
                row.child.hide();
                tr.removeClass('shown');
            });
           
        }

        else {
            // Open this row
            row.child(format(row.data())).show();
            tr.addClass("shown");
            $("#tblTransactions").dataTable({});
        }
    });

Open in new window


My problem, is that this works fine, if I have a single row in my main table, and click through to see the detailed table (tblTransactions). However, whenever there is another row, then I get a Jquery error, stating the table tblTransactions has already been initialized.

So, how can I get around this issue?
jQueryJavaScriptWeb DevelopmentJScriptDatabases

Avatar of undefined
Last Comment
Wayne Atherton

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Wayne Atherton

ASKER
Hi, thanks for responding. I'm out of the country at the moment, and don't have access to try this, but will try it and reply when i'm back
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy