2016-02-04 123 views
0

我們使用數據表插件如下綁定數據並在網格中顯示。下面是代碼:如何清除數據從網格數據表插件jQuery的?

productJs = { 
apiBaseUrl: "/api/Admin/GetProductsPurchasedOrInCart", 
dataTableID: "#products_Grid", 

ready: function() { 
    alert('yyyy'); 
}, 
jqueryDatatableSetting: { 
    "aaSorting": [], 
    "aoColumns": [ 
    { "mDataProp": "ProductName" }, 
    { "mDataProp": "Quantity" }, 
    { "mDataProp": "unitPrice" } 
    ] 
}, 

jqueryDatatable: null, 

bindJqueryControls: function (e) { 

}, 
loadProducts: function (oderNo) { 
    //alert(oderNo); 
    var apiUrl = this.apiBaseUrl + '?IsPurchased=Y&OrderNo=' + oderNo; 
    $.ajax({ 
     url: apiUrl, 
     type: "GET", 
     complete: function (resp) { 

      if (resp.status == 200 || resp.status == 201) { 
       $('#products_Grid > tbody').html(''); 
       productJs.bindDatatable(resp.responseJSON); 
      } else if (resp.status == 404 || resp.status == 400) { 

      } 
     }, 
     error: function() { 

     } 
    }); 
} 
, bindDatatable: function (records) { 

    if ($("#products_Grid_wrapper").length == 0) { 
     //it doesn't exist 
     this.productdataTableID = $(this.dataTableID).dataTable(this.jqueryDatatableSetting); 
    } else { 
     var table = $(this.dataTableID).DataTable(); 
     table.clear().draw(); 
    } 

    if (records.length) 
     this.productdataTableID.fnAddData(records); 
} 
} 

讓我解釋一下是怎麼回事:我有一個grid綁定t \與上面相同,就是orderJs。我們希望在用戶點擊訂單網格中的詳細信息按鈕時顯示訂單詳細信息。 Order Grid也使用數據表,因爲我綁定了產品的數據。

現在我已經做了:我已經完成了在產品網格中訂單號的基礎上綁定數據,它第一次正常工作。意味着當我點擊「訂單詳情」時,它會打開正確產品的彈出窗口。現在我已經關閉了彈出。現在點擊任何其他訂單的詳細信息按鈕,現在當彈出時打開它獲取舊訂單的產品+新訂單的產品。

我想在重新綁定之前清除Product Grid。

我已經嘗試了一些東西,但沒有運氣,你可以專家傢伙,請檢查我做錯了。

回答

0

大家好我得到了答案..哇..

我剛剛加入更新了我下面的方法「fnClearTable」泛函

bindDatatable: function (records) { 

    if ($("#products_Grid_wrapper").length == 0) { 
     //it doesn't exist 
     this.jqueryproductDatatable = $(this.dataTableID).dataTable(this.jqueryDatatableSetting); 
    } else { 
     this.jqueryproductDatatable.fnClearTable(); 
    } 

    if (records.length) { 

     this.jqueryproductDatatable.fnAddData(records); 

    } 
} 

感謝大家的支持... :)