Responsive mode auto close and open other views.

Responsive mode auto close and open other views.

classic12classic12 Posts: 228Questions: 60Answers: 4

Is it possible to have a max of 1 row expanded.

ie row 1 is expanded.
When expand row2 , row closes.

Cheers

Steve Warby

Answers

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    Sure - on each click to expand a row, you'd check to see if any other rows are already expanded (row().child.isShown()) and close it if needed. You could do that in a rows().every() callback.

    Allan

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Thanks allan,

    not being lazy but I can't find the on expand event.

    What is the syntax for that please.

    I presume my code should be

    on expand code----
    
    table.rows().eq(0).each( function ( index ) {
        var row = table.row( index );
     
        var data = row.data();
    
     var tr = $(this).parents('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 (the format() function would return the data to be shown)
            
            tr.addClass('shown');
        }
    
    
        // ... do something with data(), or row.node(), etc
    } );
    

    But will this close the one I've just opened if so how do i say

    close all other.

    Cheers

    Steve Warby

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    Sorry - I had missed that you were using Responsive here and it wasn't just about generic child rows.

    responsive-display is the event in question here.

    I'm mildly surprised I don't have an example demonstrating that already to be honest. I'll take a look into that if I get a chance next week.

    Allan

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Hi allan,

    did you get round to this in your busy schedule ?

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    Not yet - sorry. Its been a bit bonkers recently!

    Allan

This discussion has been closed.