insert a row in a given position

insert a row in a given position

I am populating manually my datatable using the row.add() api. After the initial load i.e. of 10 rows, trigger by a subsequent event on my UI, I need to insert a new row between the 4th and 5th row. Which is the best way to do that ?
Thanks for any hint

This question has accepted answers - jump to:


  • allanallan Posts: 56,888Questions: 1Answers: 9,042 Site admin
    edited September 23 Answer ✓

    Position of the row in the DataTable is entirely defined by the ordering applied to the table. So if you need it in a certain position, the data in that row would need to be ordered (sorted) into that position. For example, you could have an integer column which defines the position of the row and sort on that.


  • kthorngrenkthorngren Posts: 16,828Questions: 25Answers: 3,989
    Answer ✓

    When inserting a row, Datatables will display it based on the table's sorting. One option is to set up some sore of dynamic index and sort on that column. You will then need to update the index column and apply the appropriate index to the row you are adding to place it where you want.

    There might be other ways to handle this. Just depends on your data and how it can be sorted. If you want to post examples of your data we might have other ideas.


  • Posts: 7Questions: 3Answers: 0

    Ok thanks. I solved using the sort api as suggested

Sign In or Register to comment.