datatable add rows dynamically under specific existing row.

datatable add rows dynamically under specific existing row.

pramodmdpramodmd Posts: 1Questions: 1Answers: 0

Hi ,
I have this functionality where I need to dynamically create rows and want to display it under specific row. But by default if sort is enabled on first column, newly added rows are positioned based on sort. If I remove the sorting on first column, newly added rows are displayed at the end. Is there any way of getting the tablerow element created and append it after the specific row.

I tried getting the nodes of newly created rows. But since these newly added rows are not currently in the dom, but later added to dom when scrolled(using scroller.js), so it is impossible to get the nodes.

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908

    Without knowing much about your data I would say the best way is to have a hidden index column that is always sorted, maybe using orderFixed. Then when you add the row, the row's index will sort it into the desired row.

    How you generate and manage that index is up to you and your particular environment and what you are basing your insertion order on. This example may help get you started:
    https://datatables.net/examples/api/counter_columns.html

    Kevin

This discussion has been closed.