Opening child row for all selected rows.

Opening child row for all selected rows.

tangerinetangerine Posts: 3,342Questions: 35Answers: 394

I need a button which will open child rows for all selected rows.
Assuming this is a valid way to obtain the selected rows:

var selectedRows = oTable.rows({ selected: true }).row();

how can I apply row.child.show() to each item in selectedRows?
Or am I missing a better way?

This question has an accepted answers - jump to answer

Answers

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30
    edited January 2018

    I would use the code below:

    oTable.rows({ selected: true }).every( function () {
        var $tr = $(this.node());
        this.child(format($tr.data('child-value'))).show();
        $tr.addClass('shown');
    });
    

    See this post on StackOverflow for demonstration and details.


    See more articles about jQuery DataTables on gyrocode.com.

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    My apologies, @gyrocode - I should have provided more detail.
    I am opening individual child rows like this:

                row.child(getChildRow(row.data().Songs.song_id)).show();
    

    getChildRow() is the equivalent to format() in your example, and it requires the specific data id to be provided.
    How can I adapt your example to get the specific data id for passing to getChildRow()?

    Many thanks for your help.

  • kthorngrenkthorngren Posts: 20,145Questions: 26Answers: 4,736

    Does this work?

    oTable.rows({ selected: true }).every( function () {
        var $tr = $(this.node());
        this.child(format(getChildRow(this.data().Songs.song_id))).show();
        $tr.addClass('shown');
    });
    

    Kevin

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    Thanks, Kevin - but no.
    I don't have the format() function. My getChildRow() makes an ajax call to retrieve the child row data, based on the id argument supplied, and returns the data formatted appropriately..

  • kthorngrenkthorngren Posts: 20,145Questions: 26Answers: 4,736
    Answer ✓

    Sorry meant to remove the format() function (copy / paste error). I think the key is to use this.data).Songs.song_id as the parameter for the getChildRow() function.

    Kevin

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    I fixed this eventually, after taking a few steps back and looking at a bigger picture.
    Thank you @Kevin and @gyrocode.

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30
  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    Nice work, @gyrocode, thanks for letting me know.

This discussion has been closed.