Hide row child

Hide row child

silenssilens Posts: 101Questions: 40Answers: 0
edited June 2018 in Free community support

https://datatables.net/examples/api/row_details.html

I would like that when I click on a row, its daughter row will be shown and all other rows will be closed

$('#tbl_Facturas tbody').on('click', 'button.albaranes', function () {
        var tr = $(this).parents('tr');
        var row = tblFacturas.row();
        var idFact = tblFacturas.row($(this).parents()).data();
        
        if (row.child.isShown()) {//Esta mostrado
                row.child.hide();
                tr.removeClass('shown');
        }
        else 
        {
            alb_fact(idFact['id'], function (tblAlbFact) {
                row.child(tblAlbFact).show(); //Esta escondido, llamo a la función
                tr.addClass('shown'); //Muestro el hijo.
            });
        }
    });

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @silens ,

    This should do the trick for you - only one child is opened at a time.

    Cheers,

    Colin

  • silenssilens Posts: 101Questions: 40Answers: 0
    edited June 2018

    Thank you very much for answering, it works fine but I need to have the possibility of closing the same one that I open. In this way, one is always left open.

     var tr = $(this).closest('tr');
            var row = tblFacturas.row( tr );
            var idFact = tblFacturas.row($(this).parents("tr")).data();
           
            tblFacturas.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
              if (this.child.isShown()) {
                this.child.hide();
                $(this.node()).removeClass('shown');
              }
            });
    
            // Now open this row
           alb_fact(idFact['id'], function (tblAlbFact) {
                row.child(tblAlbFact).show(); //Esta escondido, llamo a la función
           });
            tr.addClass('shown');
        });
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi again, that's an easy one: http://live.datatables.net/yuhumoxo/2/edit

  • silenssilens Posts: 101Questions: 40Answers: 0

    Muchisimas gracias.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    De nada :)

This discussion has been closed.