2015-02-24 36 views
2

我正在使用JoeQuery的Stupid-Table jQuery插件對簡單表進行排序。我不知道如何刷新動態表格上的整個排序緩存。如何在動態表更新後刷新整個表的排序緩存?

updateSortVal函數允許更新單個單元格。例如:

$age_td.updateSortVal(23); 

但我怎麼能刷新整個表格整個theadtbody更換時?

這裏是我的代碼:

$.ajax({ 
    ... 
    success: function(data) { 
     $("#myTable thead, #myTable tbody").empty(); 
     if (data.data.length > 0) { 
      var $thead_tr; 
      var $tbody_tr; 
      for (var r = 0; r < data.data.length; r++) { 
       if (r == 0) $thead_tr = $("<tr>").appendTo("#myTable thead"); 
        $tbody_tr = $("<tr>").appendTo("#myTable tbody"); 
        for (var c in data.data[r]) { 
         if (r == 0) $("<th>").html(c).appendTo($thead_tr); 
         $("<td>").html(data.data[r][c]).appendTo($tbody_tr); 
         // I've tried adding `.updateSortVal(data.data[r][c]);` 
         // to the above as well, but the cache for the `th` 
         // needs to be re-cached as well, so let's do it all at once 
        } 
       } 
       // I'd like to refresh the entire stupidtable cache here 
       $("#myTable").stupidtable().show(); 
      } 
     } 
    }  
}); 

回答

2

也許你應該基本上刪除你的表,而不是清空,然後重新創建重置合適的(寬度replaceWith()爲例)

$("#myTable").replaceWith('<table id="myTable"><thead></thead><tbody></tbody></table>'); 

代替的

$("#myTable thead, #myTable tbody").empty(); 

編輯

因爲我不確定你叫什麼緩存,我做了這個小提琴。 如果您重現您的問題,您可以檢查並解釋我嗎?

Fiddle demo here

+0

好主意。但它沒有刷新緩存。我知道沒有jsfiddle這很難。感謝您的嘗試。 – Ryan 2015-02-24 17:34:30

+0

看到我編輯的答案來檢查小提琴 – 2015-02-24 18:20:50

+0

小提琴的作品!你有沒有改變愚蠢的桌子js? – Ryan 2015-02-24 18:24:11