Dynamically Add and Remove old

Dynamically Add and Remove old

dentmacdentmac Posts: 2Questions: 1Answers: 0

Hi,

I want to add rows dynamically and remove old by keeping latest 10 records only. I am pushing new rows every second, so I want to remove old rows.

Is there any API function that can keep X number of rows and remove rest?

Answers

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

    Is there any API function that can keep X number of rows and remove rest?

    No, but you can remove rows with rows().remove() - you would just need to determine which rows you want removed.

    Colin

  • dentmacdentmac Posts: 2Questions: 1Answers: 0

    can i use number of row to remove it?

    for example: row(12).remove()

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    There are lots of selectors you can use to choose the rows to delete. These are documented in the row-selector docs. One way to do this is to use rows().indexes(), along with toArray(), to get the indexes of all the rows. Then slice() the array to get the rows to remove. Remove the rows then add the new. Here is a simple example:
    http://live.datatables.net/rogalazi/1/edit

    I used order to run off ordering. You do not need to do this.

    Kevin

This discussion has been closed.