duanpin9531 2014-07-12 17:40
浏览 60

Tablesorter和保存排序

I have a table with some information. At first time it is generate from php-script and then every n-seconds check database.

Then I've installed tablesorter plugin. It's okay, but now, after getting information from database(if table was sorted by several fields) sort "configuration" resets.

So I've found some information about saveSort plugins, download jquery.tablesorter.widgets.js include it into my project. In plugin's documentation I've found some instruction like how to.

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

But it doesn't fix my problem. After getting results the saved sort resets.

So, here is the code of my script:

    $(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);

});

Here is simple table that I used.

<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>

So, no errors, everythings from tutorial, but it doesn't work good. I think I'm use this widget in a wrong way.

  • 写回答

1条回答 默认 最新

  • dongwalun2507 2014-07-14 16:29
    关注

    The saveSort widget requires:

    • jQuery v1.4.1+
    • $.tablesorter.storage utility which is also included in the jquery.tablesorter.widgets.js. I mention this in case the file was modified some how.
    • A browser that supports localStorage, or cookies (fallback method if localStorage is not supported).
    • The save sort can be enabled/disabled using the widget option

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

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算