weird behavior with child()
weird behavior with child()

in a datatable I set child rows. In a child row there is a button with onclick = (e) => { f(dtRowApi); }
where dtRowApi
is a datatable api "linked" to the parent row.
with
f(dtRowApi) {
let d = dtRowApi.data();
d.Value = "123;"
dtRowApi.data(d).invalidate();
}
the parent row is well updated.
with
f(dtRowApi) { dtRowApi.remove();}
the child row is removed but not the parent row.
Is this the expected behavior ?
How to remove the parent row knowing its dtRowApi ?
I try:
dtRowApi.child().hide();
dtRowApi.remove().draw();
the child row is hidden but the parent is not removed
dtRowApi.child().remove();
dtRowApi.remove().draw();
the child row is removed...
This question has an accepted answers - jump to answer
Answers
Looks like this should work.
Maybe you need to chain
.draw()
.It's hard to fully understand from the code snippets what is happening. Please provide a simple test case showing the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
here is the fiddle
https://live.datatables.net/losogeli/3/
when you click the remove button, only the detail is removed
Interesting problem. I'm not sure why this does not remove the row :
My guess is that
row
has a stale reference to the Datatables row. Maybe @allan can shed some light on this.However if you pass
row
into therow()
API it does work, for example:Updated test case:
https://live.datatables.net/losogeli/4/edit
Not sure if it would be best practice to use
row().child.remove()
to make sure the memory is released before removing the parent row. Maybe something like this:https://live.datatables.net/zidefadu/1/edit
Kevin
Rigth now I take
Thank you
(How did you come up with this solution? (recreation of the row with the row!))
First I added
table.row().remove().draw()
to the event handler. When it worked it reminded me of seeing similar questions (losing the object reference) when using child rows. I figured passing the row reference torow()
would work.Kevin