2012-10-11 87 views

回答

4

在等待答案時,我終於找到了它:fnDraw函數就是我所需要的。

它描述at the beginning of the API section,但我沒有打擾閱讀全部內容:

你必須使所需的服務器調用來操縱你的所需數據,然後簡單地redraw the table (fnDraw)查看新數據。

+0

這應該是可以接受的答案。 – nrodic

1

嘗試調用:

$("#Table1").fnDestroy().dataTable(); 

這應該重建它...

+1

+1謝謝。但我只是找到了'fnDraw'方法,這可能是一個更好的方法。 – Lou

+0

同意。很好的發現。 –

1

添加這個地方:

$.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; 
    var aData = []; 

    this.oApi._fnServerParams(oSettings, aData); 

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

     /* Got the data - add it to the table */ 
     var aData = (oSettings.sAjaxDataProp !== "") ? 
      that.oApi._fnGetObjectDataFn(oSettings.sAjaxDataProp)(json) : json; 

     for (var i=0 ; i<aData.length ; i++) 
     { 
      that.oApi._fnAddData(oSettings, aData[i]); 
     } 

     oSettings.aiDisplay = oSettings.aiDisplayMaster.slice(); 
     that.fnDraw(); 

     if (typeof bStandingRedraw != 'undefined' && bStandingRedraw === true) 
     { 
      oSettings._iDisplayStart = iStart; 
      that.fnDraw(false); 
     } 

     that.oApi._fnProcessingDisplay(oSettings, false); 

     /* Callback user function - for event handlers etc */ 
     if (typeof fnCallback == 'function' && fnCallback != null) 
     { 
      fnCallback(oSettings); 
     } 
    }, oSettings); 
} 

然後調用它像這樣:

oTable = $(".dt").dataTable(); 
oTable.fnReloadAjax(); 

信用:http://datatables.net/plug-ins/api