Expand one row's details and collapse all others

Expand one row's details and collapse all others

dmolavidmolavi Posts: 65Questions: 0Answers: 0
edited July 2011 in General
I'm using the example code from http://datatables.net/release-datatables/examples/api/row_details.html to expand/collapse row details, but would like to tweak it to collapse any already open details when a new row is clicked, so that only one row's details are ever shown at a time. Without recursing through the entire table, is there an efficient way of doing this? I was thinking of storing the expanded row's ID in a variable, and just toggling the row when a new row is clicked and updating the variable with the new row's ID, but I haven't had enough coffee yet this morning to figure out how to make this work. You can see a working example at http://www.modeltraintracker.com/sandbox/ (login: testuser , password: testuser ).

Replies

  • dmolavidmolavi Posts: 65Questions: 0Answers: 0
    I've got it partway there, clicking a new row will collapse the old row, BUT...
    1. The expand/collapse image on the old row is not updated, and
    2. The old row cannot be expanded again...
  • dmolavidmolavi Posts: 65Questions: 0Answers: 0
    w00t, got it working. Check the link in the first post and you can see where i've tweaked the code.
  • srilathasrilatha Posts: 1Questions: 0Answers: 0
    Hi dmolavi,
    I am looking for data table config, to expand only one row at a time.
    How did you achieve this?
    Would you mind sharing the sample code to me.

    Thanks in advance.
  • dmolavidmolavi Posts: 65Questions: 0Answers: 0
    You can view the source in the page I have linked above.
  • phuhai_dtphuhai_dt Posts: 7Questions: 0Answers: 0
    Hi dmolavi,

    Can you tell me how to do that.
  • phuhai_dtphuhai_dt Posts: 7Questions: 0Answers: 0
    Hi dmolavi,

    It worked by using an array to store nTr node and then before a row span, i close all node in array
This discussion has been closed.