weird behavior with child()

weird behavior with child()

tschmittschmit Posts: 20Questions: 6Answers: 0
edited April 9 in Free community support

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

  • kthorngrenkthorngren Posts: 21,889Questions: 26Answers: 5,057

    dtRowApi.remove().draw();

    Looks like this should work.

    f(dtRowApi) { dtRowApi.remove();}

    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

  • tschmittschmit Posts: 20Questions: 6Answers: 0

    here is the fiddle
    https://live.datatables.net/losogeli/3/

    when you click the remove button, only the detail is removed

  • kthorngrenkthorngren Posts: 21,889Questions: 26Answers: 5,057
    edited April 10 Answer ✓

    Interesting problem. I'm not sure why this does not remove the row :

         row.remove();
         dtApi.draw();
    

    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 the row() API it does work, for example:

    dtApi.row( row ).remove().draw();
    

    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:

        row = dtApi.row( row );
        row.child.remove();
        row.remove();
        dtApi.draw();
    

    https://live.datatables.net/zidefadu/1/edit

    Kevin

  • tschmittschmit Posts: 20Questions: 6Answers: 0

    Rigth now I take

    dtApi.row( row ).remove().draw();
    

    Thank you

    (How did you come up with this solution? (recreation of the row with the row!))

  • kthorngrenkthorngren Posts: 21,889Questions: 26Answers: 5,057
    edited April 10

    How did you come up with this solution?

    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 to row() would work.

    Kevin

Sign In or Register to comment.