Hide Open Child Rows
Hide Open Child Rows
raisonco
Posts: 17Questions: 5Answers: 0
I have created a child row that opens just like this example:
http://olgatsib.comcdn.datatables.net/blog/2014-10-02
I want to make it so only one child can be shown at a time.
So IF one child row is already shown, then hide that first and then show the row that has been clicked on.
I have added a class to the added tr row when it is created. I now want to have some code that closes/hides it.
I have written the following but it is not working yet. Any advice appreciated.
var siblingTr = $(this).parent().parent().children('tr.child-row').first();
if (siblingTr.length) {
console.log('hide siblings');
var siblingRow = table_days_free.row( siblingTr );
siblingRow.child.hide();
}
This discussion has been closed.
Answers
The example you are showing adds a class when it is shown and removes it when it is hidden which I don't see you doing.
I would make a general statement to close everyone without checking to see if it is open, then open the target.
Hi,
there is a plug in that will give you this functionality. It is available here:
https://github.com/DataTables/Plugins/blob/master/features/slidingChild/js/sliding-child.js
One of the options is 'toggleChild'. When set to true, only a single child will be allowed to show. Expanding a different child will automatically collapse the previously showing one. Clicking an already expanded row will collapse it. Hope that helps