How to delete the last (last in only) row??
How to delete the last (last in only) row??
UPEngineer
Posts: 93Questions: 0Answers: 1
I have a weird question or problem.
I have an application and I am using Datatables as I use it throughout the web app.
I have a table that may have 10-50 records or so when the page is first opened. I have a radio button input that when clicked, it will update the status to Verified. And then I delete it using fnDeleteRow function.
Works great until I get to the last row, meaning 1 row. When I click this, I get an error. I have tried using and if/then statement to set fnDeleteRow redraw to false, but still no luck.
If you could point me in right direction, I would appreciated it. Or if this is not possible at all, either way.
What I would like to do is one the last record is deleted, display something to that effect.
Hope not too confusing.
I have an application and I am using Datatables as I use it throughout the web app.
I have a table that may have 10-50 records or so when the page is first opened. I have a radio button input that when clicked, it will update the status to Verified. And then I delete it using fnDeleteRow function.
Works great until I get to the last row, meaning 1 row. When I click this, I get an error. I have tried using and if/then statement to set fnDeleteRow redraw to false, but still no luck.
If you could point me in right direction, I would appreciated it. Or if this is not possible at all, either way.
What I would like to do is one the last record is deleted, display something to that effect.
Hope not too confusing.
This discussion has been closed.
Replies
But I would like to keep it non-server side if possible.
This is the error:
jquery.dataTables.min.js:59 Uncaught TypeError: Cannot read property 'length' of undefined
If it's anything like php, it could be the attempt to loop over a single item that causes the error.
In my case I was setting all of the variables into an associative array in PHP called $response, and then using echo json_encode($response); to spit it out at the end of my script. I just needed to define $response['aaData'] = array(); so that it would still exist if there were no rows.
Now when I delete the final row, or load a page that had no rows to begin with, things work fine :)