insert a row in a given position

insert a row in a given position

Hello,
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:

Answers

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    edited September 2022 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.

    Allan

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    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.

    Kevin

  • lucioanneoalex@gmail.comlucioanneoalex@gmail.com Posts: 7Questions: 3Answers: 0

    Ok thanks. I solved using the sort api as suggested

Sign In or Register to comment.