How can close child rows on change page?
How can close child rows on change page?
david.papini
Posts: 21Questions: 5Answers: 0
Hi i've a child rows from ajax call. I need to close all child opened when user change page.
How can do it?
Thank you
This discussion has been closed.
Answers
This example from this thread shows how you can close them all - it only allows one open. You could do the same in a
draw
orpage
,Colin
Thank you 4 your answer, but i need to close opened child on change page, but i can't use draw and i don't trigger when click on number page.
The simplest case is to use
rows().every()
to loop all the rows. You can then userow().child.isShown()
to detemine if the child is shown and if so then eitherrow().child.hide()
orrow().child.remove()
. You can do things to be more efficient if you have lots of rows. If you need help with this part then post more information about what you have and want.Kevin
ok, it'a a possibility.
where i can use row().every() on 'draw' event?
Yes. If you do that then use
selector-modifier
of{page:'current'}
to just iterate the visible rows.EDIT: Just notice Colin's reply. At least we gave consistent answers
Kevin
this is my code
the issue is that when i expand child row, by button, i close it on same time...
I put your code in this test case and it doesn't exhibit that problem.
However there are a couple other issues.
tr.removeClass('details');
is probably not changing the row details button. The class should beshown
and$(table).closest('tr');
wasn't giving the expected row in the test case. I updated the code based on Colin's example. Also commented outdetailRows.splice(row.index, 1);
as I don't have that array defined.Please update the test case to replicate the problem.
Kevin
Thank you, i can't update you test, but i think tha my issue is on mode to load data into table
So when i trigger 'draw' i close on my hand the child that i 've opened
Just to make sure I understand the problem. When you click the plus sign button the child opens then closes. Is this correct?
I'm not sure how the above code would cause that as the
draw()
APIs are called after you load the table data but before you reopen the child rows.If you are unable to show use the problem then I would start by adding a console.log statement to your click event to open the rows. Does it execute more than once when clicking the button? Are you calling
draw()
in the event?Just as an FYI... Here is an alternative way to reopen the child rows after reloading the table which eliminates the need to call something to click the button:
http://live.datatables.net/qolevune/1/edit
Kevin
yes you have get me.
the api is called after load data to reposition on last page and reopen the child before the update.
very update data i reload, by ajax, the full datatable.
this is the code to load chid
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
I'm still not seeing anything that would show why the
$('#tablePianodicaricoMaster').on('draw.dt', function ()
event would cause the row you just clicked to show then hide. Is there another place in the code that might execute something to cause Datatables to draw, like calling a search, order or page API. Or maybe something that callsonRowDetailsClick()
?I would use console log statements in each event to see when they are called. Maybe you will see one of them unexpectedly called when you open a child row.
Kevin
i find it, i think.
when i load the data child
this code call me the draw.dt event of my master table
how can i fix it?
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
You are using the
draw()
API with this$(detailsTableOpt).DataTable()....
table. But your draw event,$('#tablePianodicaricoMaster').on('draw.dt', function () {
, is applied to a different table. So, thatdraw()
should not invoke this event.What happens if you comment out the statement
row.child.hide();
in the event?You have a lot going on and its difficult for us to peice together your code snippets. As Colin said can you post a link to your page so we can take a look.
Kevin
DataTable > click td.details-control [Wed Feb 19 2020 14:44:29 GMT+0100 (Ora standard dell’Europa centrale)]
PianoDiCarico:1450 DataTable > onRowDetailsClick [Wed Feb 19 2020 14:44:29 GMT+0100 (Ora standard dell’Europa centrale)]
PianoDiCarico:1707 DataTable > draw.dt [Wed Feb 19 2020 14:44:29 GMT+0100 (Ora standard dell’Europa centrale)]
PianoDiCarico:1708 console.trace
this is my stack trace, last draw.dt is called from this row
var detailsTableOpt = $('#tablePianodicaricoDetail' + rowData.CdGiro).dataTable({
i can't public my page, because i put in fail my production.
Initializing a Datatable will call draw() but it will be for the table being initialized. The child detail table in your case. I suspect that
PianoDiCarico:1707 DataTable > draw.dt
is the drawing of the child table.You didn't answer my question. What happens if you comment out
row.child.hide();
?Seems like your full Datatables code might be long. Even if it doesn't run maybe you can post it in a test case. We can scan through to see if anything obvious stands out.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
if i comment out row.child.hide() child is opened
Sounds like something else on your page is causing the
tablePianodicaricoMaster
table to draw. I might be missing it but I don't see it in any of the above code. There is this code:But that seems independent of your
onRowDetailsClick()
function. Unless you can post your code so we can see it you will need to trace through it to find out why thetablePianodicaricoMaster
table is redrawing when open a child row.Kevin
http://live.datatables.net/xupigedu/1/edit
When you open the child row does it close right away or maybe after a short period of time?
I see this that may draw the
tablePianodicaricoMaster
every 60 seconds.Kevin
yes but if only flrefresh is checked onpage
Interesting. I put your relevant code into a test case:
http://live.datatables.net/marimelo/2/edit
I updated the click event to this:
With
$('#tablePianodicaricoMaster').on('draw.dt'
the event executes even when the child Datatables draws, for example:Changing 'draw.dt' to 'draw' fixes the issue. Maybe @allan or @colin can explain why
$('#tablePianodicaricoMaster').on('draw.dt'
is invoked with the child Datatable.Working example with
$('#tablePianodicaricoMaster').on('draw', function (e, settings) {
:http://live.datatables.net/xanajisu/1/edit
Kevin
I looked at this further. You will need to use
draw.dt
asdraw
won't work for your particular solution. Since the child is a Datatable it'sdraw
events bubble up to the parent Datatable. You will need to use Event.stopPropagation for your child Datatables, for example:Here is the updated example:
http://live.datatables.net/xanajisu/3/edit
Kevin
thank you, now it's working!