2014-07-12 53 views
0

我有一個表的一些信息。 它首次從php-script生成,然後每隔n秒鐘檢查一次數據庫。Tablesorter和保存排序

然後我安裝了tablesorter插件。沒關係,但現在,從數據庫獲取信息後(如果表格按多個字段排序),重新排序「配置」。

所以我找到了一些關於saveSort插件的信息,下載jquery.tablesorter.widgets.js將它包含到我的項目中。在插件的文檔中,我發現了一些指令,如how to

$("table").tablesorter({ 
    widgets: ["saveSort"] 
}); 

但它不能解決我的問題。獲得結果後,保存的排序將重置。

所以,這裏是我的腳本代碼:

$(document).ready(function(){ 

     $("table").tablesorter({ 
     widgets: ["saveSort"] 
    }); 

    function get_op(){ 

     var dataSend = "to teh mooon"; 

     jQuery.ajax({ 
      type: "POST", 
      url: "get_url", 
      dataType:"html", 
      data:dataSend, 

      success:function(response){ 
       $("#recent_op tbody").html(response); 
       $("#recent_op").trigger("update"); 

      }, 
      error:function (xhr, ajaxOptions, thrownError){ 
       $("#recent_operations").html(thrownError); 
      } 
     }); 

    } 
    setInterval(function(){get_op()}, 10000); 

}); 

下面是簡單的表,我用。

<table class="table table-bordered table-hover table-striped tablesorter" id = "recent_op"> 
     <thead> 
     <tr> 
      <th>header # <i class="fa fa-sort"></i></th> 
      .... 
      </tr> 
     </thead> 

     <tbody> 
      <tr> 
      <td>Body</td> 
      .... 
      </tr> 
        .... 
      <tr> 
       <td>Body</td> 
       .... 
      </tr> 
     </tbody> 
    </table> 

所以,沒有錯誤,教程的一切,但它不工作的好。我想我以錯誤的方式使用這個小部件。

回答

0

saveSort插件需要:

  • jQuery的V1.4.1 +
  • $.tablesorter.storage工具,它也被包括在jquery.tablesorter.widgets.js。我提到這個以防萬一文件被修改了一些方法。
  • 支持localStorage或cookie的瀏覽器(不支持localStorage的回退方法)。
  • 保存排序可以使用插件選項

    $(function(){ 
        $("table").tablesorter({ 
        widgets: ["saveSort"], 
        widgetOptions : { 
         // if false, the sort will not be saved for next page reload 
         saveSort : false 
        } 
        }); 
    }); 
    
啓用/禁用