If DataTable with data then has AJAX update with 0 rows, "sZeroRecords" doesn't display

If DataTable with data then has AJAX update with 0 rows, "sZeroRecords" doesn't display

JasonOJasonO Posts: 2Questions: 0Answers: 0
edited March 2014 in Bug reports
I'm not sure if this is a bug in DataTables or the function I am using.

I'm able to delete records from the database at a click of a button (or two..). My DataTable updates live from the server via an AJAX call which works fine. The rows get removed from the table not a problem and table updates fine.. until you get to the last one.

If deleting the last and only row in a table the row doesn't delete from the DataTable (even though the data is returning 0 rows via AJAX). I use fnReloadAjax() and no matter how many times I run this, the row will not delete from the table unless a new one is added to the database, kicking in the load which shows the correct data. I think the condition check for the "sZeroRecords" message to display is not checking on an AJAX call after the table has initialised. Is this the function I am using (see below) or something within DataTables code?

The basics of my code is..

Send query of row delete to server via AJAX,
IF return result is successful (returned via JSON Message created from PHP Database query)
THEN do fnReloadAjax() on relevant DataTable

The above works fine when you have a few rows, the table refreshes with the deleted row removed, but like I said if you come to remove the final row of a Database the row stays within the table and it doesn't deal with the now empty data call via fnReloadAjax().

I don't know if fnReloadAjax is a function written by yourself Allan or I've pulled it from somewhere else? This is what I have..

[code]$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
{
if ( typeof sNewSource != 'undefined' && sNewSource != null )
{
oSettings.sAjaxSource = sNewSource;
}
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
var iStart = oSettings._iDisplayStart;

oSettings.fnServerData( oSettings.sAjaxSource, [], function(json) {
/* Clear the old information from the table */
that.oApi._fnClearTable( oSettings );

/* Got the data - add it to the table */
for ( var i=0 ; i

Replies

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    > If deleting the last and only row in a table the row doesn't delete from the DataTable

    Can you link us to a page showing that problem please?

    Allan
  • JasonOJasonO Posts: 2Questions: 0Answers: 0
    It's built within a private system, I'll see if I can setup an independent page with this happening.
This discussion has been closed.