FnDeletrow and FnDraw not working sometimes

FnDeletrow and FnDraw not working sometimes

bspbsp Posts: 7Questions: 0Answers: 0
edited August 2011 in General
hi,
I am trying to remove a row from the datatable once the row has been deleted from the server using oTable.fnDeleteRow( 0 );. This works sometimes and sometimes the row is not deleted and I have to refresh the page to reload data from server , any idea why ? I also have the same issue with oTable.fnDraw(); I call this function to redraw the datatable once a set of rows are deleted from the server based on an ajax post on a button click. Any help would be appreciated. I am not sure why this is happening randomly.
some settings for that table is as follows:
'bServerSide' : true,
'bAutoWidth' : false,
'bStateSave': true,
'bJQueryUI': true,
'sPaginationType': 'full_numbers',

Replies

  • StephanStephan Posts: 20Questions: 0Answers: 0
    [quote]bsp said: This works sometimes and sometimes the row is not deleted and I have to refresh the page to reload data from server , any idea why ? I also have the same issue with oTable.fnDraw(); I call this function to redraw the datatable once a set of rows are deleted from the server based on an ajax post on a button click. [/quote]
    Sounds like sometimes the redraw happens before the deletion of the row from your database takes place.
    When do you call fnDraw/fnDeleteRow()? In the success handler of the ajax.post? You need to ensure, that the serverside deletion of your row is done before redrawing the table.
    fnDeleteRow by default redraws the table (http://datatables.net/api#fnDeleteRow).
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    With server-side processing fnDeleteRow is effectively useless. It will delete the row on the client-side and then redraw the table as Stephan says. This will then reload the data from the server and draw that - with your deleted row, since the server doesn't know you deleted it!

    So what you need to do is send an Ajax call to the server to delete the row, and then simply call fnDraw in the Ajax callback function.

    Allan
  • bspbsp Posts: 7Questions: 0Answers: 0
    edited August 2011
    Hi Allan,

    I am doing the fnDraw/fnDeleteRow() after the successfully getting a response from the ajax call to server which deletes the data and when I refresh the page I can see that the row is deleted which means it is deleting from the database. My understanding is that we fnDraw() makes a call to the server and draws the table again with fresh server data. In my case this works sometimes and then stop removing row / redrawing the table without any specific reason.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Sounds like your code could be halted at some point and so not finishing up the function. There must be an error or something causing the sequence to end early.

    If you post a link we can take a look through the debugger.
  • mcbutterbunsmcbutterbuns Posts: 7Questions: 0Answers: 0
    This is strange. We are experiencing the same issue. A separate Ajax call to delete the record. When the call completes, we call fnDraw() which does not go back to the server, it just reuses whatever is in aoData.

    We are not calling fnDeleteRow.
  • mcbutterbunsmcbutterbuns Posts: 7Questions: 0Answers: 0
    It would appear that the pipelining plugin we are using is preventing the request from going through. It is using the cached data to redraw the table.
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Well if you are using the pipelining code it has a cache on the client-side which is obviously going to be out of date when you modify the data on the server-side, and it can't know that unless you tell it (since there isn't an automatic sync). You need to tell the cache to be cleared and reload the data - oCache.iCacheLower = -1 would do that.

    Allan
  • mcbutterbunsmcbutterbuns Posts: 7Questions: 0Answers: 0
    Yes, that looks like it would be a simple solution.

    We may also try to remove the record from the pipeline's cache so that we don't have to round trip to the server just for a delete.
This discussion has been closed.