How to delete the last (last in only) row??

How to delete the last (last in only) row??

UPEngineerUPEngineer Posts: 93Questions: 0Answers: 1
edited August 2010 in General
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.

Replies

  • UPEngineerUPEngineer Posts: 93Questions: 0Answers: 1
    BTW, I am not using server-side processing on this table if that helps. I guess, I could try to implement it some way using server side processing.

    But I would like to keep it non-server side if possible.
  • rewenrewen Posts: 74Questions: 2Answers: 0
    I have the same issue, however I am using server-side processing.

    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.
  • rewenrewen Posts: 74Questions: 2Answers: 0
    If anyone is having this issue with server-side, I found that it can be caused by aaData not being sent through JSON. It needs to be sent, even if it's empty.

    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 :)
This discussion has been closed.