Why do my child rows not show its contents after using the destroy option?

Why do my child rows not show its contents after using the destroy option?

dt_userdt_user Posts: 51Questions: 16Answers: 0

Good night.
In my code I need to change the contents of the tbody in datatables based on a person's name that is clicked.
Using the destroy option works great i can show different people information and i don't get the cannot reinitialize datatables error. BUT!! when i refresh the page the child rows work perfectly for the person I start with. When i select another person the child rows wont open.

Please let me know how i can fix this issue.
Thank you

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @dt_user ,

    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

  • dt_userdt_user Posts: 51Questions: 16Answers: 0

    Ok. I followed the link you provided and I am using live.datatables.net. I placed my code in it. But I can't populate the datatables because I get data from my database.
    Do you still want to see the code in live.datatables.net?
    Please let me know.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    It depends if you want help ;) Without being able to see the issue, it's hard to make recommendations. Can you link to your page, or abstract the issue to a simple test case on live.datatables.net so we can see the problem? We don't need server data, we just need to see the problem.

  • dt_userdt_user Posts: 51Questions: 16Answers: 0

    ok Colin, I tried to replicate my actual code. The problem experienced here is exactly what I am experiencing now. The only difference is that in my actual code I only have one initialization of datatables that is loaded with different data based on the button pressed. In my example I needed to have two so I could show you how I move between the buttons to load different data in the same DataTable.

    The link: http://live.datatables.net/givixejo/1/

    Please let me know how I can fix my problem with the child rows not showing for the second person(button).
    Thank you.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    edited July 2019 Answer ✓

    Hi @dt_user ,

    The problem is because you were accumulating the on events - the old ones weren't being removed. I added an off to remove the previous listeners near the start of your tab_clicked() function, and it seems to be doing what you want. See here.

    Hope that does the trick,

    Cheers,

    Colin

  • dt_userdt_user Posts: 51Questions: 16Answers: 0

    Thank you so much!!!

This discussion has been closed.