将列动态添加到由jQuery的tablesorter管理的表中 [英] Adding columns dynamically to a table managed with jQuery's tablesorter

查看:49
本文介绍了将列动态添加到由jQuery的tablesorter管理的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在具有要由jQuery的表排序器排序的表的网页上,具有将列动态添加到表中的功能.当发生这种情况时,我调用trigger("update")和trigger("appendCache")以使tablesorter能够按新列进行排序(我也尝试过再次调用tablesorter()).但是,在单击标题单元格之前,用于排序的小部件不会出现在新列中.

On a web page that has a table that is being sorted by jQuery's tablesorter, there is functionality to add columns to the table dynamically. When this happens I call trigger("update") and trigger("appendCache") to get tablesorter to be able to sort by the new column (I have also tried calling tablesorter() again). However, the widgets for sorting do not appear in the new column(s) until I click in the header cells.

我的问题是,有人知道如何使小部件立即显示吗? 谢谢 问候 杰森

My question is does anybody know how to get the widgets to appear immediately? Thanks Regards Jason

推荐答案

   <head>

    <title>jQuery plugin: Tablesorter 2.0</title>

    <link rel="stylesheet" href="css/jq.css" type="text/css" media="print, projection, screen" />

    <link rel="stylesheet" href="../themes/blue/style.css" type="text/css" media="print, projection, screen" />

    <script type="text/javascript" src="../jquery-latest.js"></script>

    <script type="text/javascript" src="../jquery.tablesorter.js"></script>

    <script type="text/javascript">

    $(function() {      

$(document).ready(function()
    {
        $("#myTable").tablesorter();
    }
);


    }); 
    function append(){
        var table = $("#myTable");
        $(table).remove();
        var tr = $("<tr></tr>");
        $("<td></td>").html('Test').appendTo(tr);
        $("<td></td>").html('test').appendTo(tr);
        $("<td></td>").html('test@gmail.com').appendTo(tr);
        $("<td></td>").html('$5.00').appendTo(tr);
        $("<td></td>").html('http://www.test.com').appendTo(tr);
        $(tr).appendTo(table);
        $(table).appendTo($('#tableholer'));
        $("#tableholer table").tablesorter();
    }

    </script>

</head>
<body>
    <div id="tableholer">
    <table id="myTable" class="tablesorter">
    <thead>
    <tr>
        <th>Last Name</th>
        <th>First Name</th>
        <th>Email</th>
        <th>Due</th>
        <th>Web Site</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>Smith</td>
        <td>John</td>
        <td>jsmith@gmail.com</td>
        <td>$50.00</td>
        <td>http://www.jsmith.com</td>
    </tr>
    <tr>
        <td>Bach</td>
        <td>Frank</td>
        <td>fbach@yahoo.com</td>
        <td>$50.00</td>
        <td>http://www.frank.com</td>
    </tr>
    <tr>
        <td>Doe</td>
        <td>Jason</td>
        <td>jdoe@hotmail.com</td>
        <td>$100.00</td>
        <td>http://www.jdoe.com</td>
    </tr>
    <tr>
        <td>Conway</td>
        <td>Tim</td>
        <td>tconway@earthlink.net</td>
        <td>$50.00</td>
        <td>http://www.timconway.com</td>
    </tr>
    </tbody>
    </table>
    </div>
    <input type="button" onclick="append()" value="append"/>
</body>

在追加的情况下可以使用.如果我不确定,请尝试删除

In case of append this would work. in case of delete try same though i am never sure

这篇关于将列动态添加到由jQuery的tablesorter管理的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆