Best way to do a mass show child

Best way to do a mass show child

aquaShockaquaShock Posts: 1Questions: 1Answers: 0

i am looking for the best way to do a mass show child

currently i have

datatable.rows([ids]).nodes().to$().each((index,tr) => {
    let row = datatable.row( tr );
    row.child( "<label>NOT THE MOMMA</label>" );
    row.child.show();
    $(tr).addClass('shown');
})

it seems like the table is redrawn each time (guessing from .show())
with a table of 2000+ rows (no paging) draws can get pricey.
Just wondering if there is a way to 'que' up the child shows so i don't have 2000+ redraws, kinda like how add row 'ques' up new rows and waits for the .draw() to visually add them

Answers

  • DonSoloDonSolo Posts: 3Questions: 1Answers: 0

    Here's how I did it (not saying it's the best way):
    Note, my child row text is placed in a data-child-note attribute in the table rows.

    <tr data-child-note="Hello World">

        Sys.Application.add_load(function () {
            var data = $('table.datatables').DataTable({
                fixedHeader: {
                    footer: true,
                    header: true,
                    headerOffset: 60
                },
                lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
                retrieve: true
            });
            data.rows().every(function () {
                if (!this.child.isShown()) {
                    var tr = $(this.node());
                    var note = tr.data().childNote;
                    if (note != null && note.length > 0) {
                        this.child(note).show();
                        this.child().addClass(tr.attr('class'));
                    }
                }
            });
        });
    

    There is a defect in the every function call that only processes the first table (if you have more than one table).

    If that applies to you, check out the details here: https://datatables.net/forums/discussion/57813/problem-with-multi-table-initialization#latest

This discussion has been closed.