Hide "Expand"-Icon on empty data ("Row Details")
Hide "Expand"-Icon on empty data ("Row Details")
jupix
Posts: 15Questions: 4Answers: 0
Hi all,
I tried this function and it works fine: https://datatables.net/examples/server_side/row_details
It is possible to show the green "+" icon only on lines with existing data (data in row details)?
I also have some items with empty data in row details and I dont want to show the expand-button here.
Other question:
Is there a way to create a button: "expand all" / "collapse all"
Thanks
jup
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @jupix ,
In that example, it's just using CSS to show the icon, but you could just as easily do something in one of the available callbacks:
createdRow
orrowCallback
. There, you could see if there is child information, and add (or remove depending on your logic) the '+' at that time.With the expand all/collapse all, yep, you could run code to do that. This example here is closing all opened child rows, thereby ensuring only one is displayed at a time. You could just as easily modify that example to open all when triggered by a button or some such,
Cheers,
Colin
Hi!
Thanks for your input.
I just did it the expand/collapse-function and it woks well ...:
<a href="#" onclick="closeAll()">Close</a>
function closeAll() { table.rows().every( function ( rowIdx, tableLoop, rowLoop ) { if (this.child.isShown()) { this.child.hide(); $(this.node()).removeClass('shown'); } }); } function expandAll() { table.rows().every( function ( rowIdx, tableLoop, rowLoop ) { if (!this.child.isShown()) { this.child( format(this.data()) ).show(); $(this.node()).addClass('shown'); } }); }<a href="#" onclick="expandAll()">Expand</a>
But the other thing sounds hard ! (only show "+" if data is existing)
Could you also provide an example please ?!
thanks
jup
Hi @jupix ,
Here you go - this is the example before, but now the child rows won't be available if you the 'Office' column is 'London'. You could use this as a template,
Cheers,
Colin
Hi Colin,
the link provided is the same as above?!
No changes in the code...
That was odd, here it is again (I cloned another table): http://live.datatables.net/wayitifo/1/edit .
The important bit of code is:
Cheers,
Colin
@colin you must have posted the wrong link for your example.
Here is an example which doesn't display the expand button if there is no data available. It uses
createdRow
to check the data.http://live.datatables.net/pifugoki/1/edit
Kevin
Cool - I got it
Thanks so much