Opening child row for all selected rows.

Opening child row for all selected rows.

tangerinetangerine Posts: 2,081Questions: 14Answers: 230

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: 112Questions: 5Answers: 29
    edited January 5

    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: 2,081Questions: 14Answers: 230

    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: 2,772Questions: 19Answers: 610

    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: 2,081Questions: 14Answers: 230

    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: 2,772Questions: 19Answers: 610
    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: 2,081Questions: 14Answers: 230

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

  • gyrocodegyrocode Posts: 112Questions: 5Answers: 29
  • tangerinetangerine Posts: 2,081Questions: 14Answers: 230

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

Sign In or Register to comment.