Select previous row after row deleted in sorted ajax supplied datatable?

Select previous row after row deleted in sorted ajax supplied datatable?

snorkel12068snorkel12068 Posts: 6Questions: 3Answers: 0

Hi,
Just wondering if there is a best practice way to select the previous row after a row is deleted?
I came up with something that uses table.rows().indexes() but it seems a bit hackish. basically I use indexOf to get the key and the decrement it then after the row is deleted from database and I get ajax response then I get the physical row index like this rowindex = currentindexes[key] and then use the standard row selector syntax. ( or something like that I may have explained it wrong LOL)

Thanks

Answers

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

    Hi @snorkel12068 ,

    When you say row deletion, is that using Editor, or just the DataTables API call row().delete()? Your approach would work, if you're not ordering or searching, as that would affect the ordering. I can't think of an easy way to do, especially if you have paging enabled too.

    Cheers,

    Colin

  • snorkel12068snorkel12068 Posts: 6Questions: 3Answers: 0

    Hi,
    Yes I am using the API to remove the row after it's deleted in the database.
    I refresh the currentindex var prior to each delete so it's fresh, seems to be working ok even if the user sorts and moves around the pages.
    I was just wondering if their was a prior or prev selector that I had missed in the docs.

This discussion has been closed.