【问题标题】:Tablesorter and search表格排序器和搜索
【发布时间】:2013-12-06 07:52:19
【问题描述】:

我有一张大桌子,我想在上面添加搜索功能。我使用 tablesorter 对列进行排序,并使用教程在开头添加另一列以对行进行编号。但是搜索不起作用。这是我的代码:

HTML

<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="/static/js/jquery.tablesorter.pager.js"></script>
<script src="/static/js/jquery.quicksearch.js" type="text/javascript"></script>
    <table id="myTable" class="table table-bordered tablesorter">
       <thead>

       </thead>
       <tbody>

       </tbody>
       <tfoot>
         <tr style="display:none;">
             <td colspan="5">
                 No rows match the filter...
             </td>
        </tr>       
       </tfoot>
    </table>
    <div id="pager" class="pager">
        <form>
             <img src="/static/blue/first.png" class="first"/>
             <img src="/static/blue/prev.png" class="prev"/>
             <input type="text" class="pagedisplay"/>
             <img src="/static/blue/next.png" class="next"/>
             <img src="/static/blue/last.png" class="last"/>
             <select class="pagesize">
             <option value="10">10 per page</option>
             <option value="20">20 per page</option>
             <option value="50">50 per page</option>
             </select>
       </form>
    </div>

这是我的 javascript:

<script>
$(document).ready(function() 
    {
    $.tablesorter.addWidget({
    id: "numbering",
    format: function(table) {
        var c = table.config;
        $("tr:visible", table.tBodies[0]).each(function(i) {
            $(this).find('td').eq(0).text(i + 1);
        });
    }
});


    $("table").tablesorter({widgets: ['numbering'],sortInitialOrder: 'desc', sortList: [[2,1]],headers: {0: {sorter: false}}})
    .tablesorterPager({container: $("#pager")});

    $("#myTable tbody tr").quicksearch({
            labelText: 'Search: ',
            attached: '#myTable',
            position: 'before',
            delay: 100,
            loaderText: 'Loading...',
            onAfter: function() {
                if ($("#myTable tbody tr:visible").length != 0) {
                    $("#myTable").trigger("update");
                    $("#myTable").trigger("appendCache");
                    $("#myTable tfoot tr").hide();
                }
                else {
                    $("#myTable tfoot tr").show();
                }
            }
        });

    }

</script>

我没有看到任何错误。只是没有搜索功能。

【问题讨论】:

    标签: javascript jquery tablesorter


    【解决方案1】:

    似乎快速搜索附加到#table,而不是#myTable,这是您共享的 HTML 中表格的 ID。

    【讨论】:

    • 该死...总是这样 :P 我搜索了一个严重的错误,但我忘记了拼写错误。非常感谢。
    • 搜索现在在那里,但它没有加载任何内容。 :(
    • 我可以大胆地建议你试试我的fork of tablesorter...这里是demo of it working with quicksearch
    【解决方案2】:

    您可能想试试datatables.js/。它是一个 jQuery 插件,可以完成您尝试构建的工作,并且实现起来非常简单。

    实现它的代码(默认有分页、搜索、列排序等)是这样的。

      $('#example').dataTable();
    

    【讨论】:

    • 我是否有 addwidget 功能来为行添加编号列?
    • 有很多工作示例,您可以在这里查看link。从基础知识到启动和运行到交互式表格的所有内容。看看一些例子,看看只是想要插件提供
    猜你喜欢
    • 2015-08-27
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    相关资源
    最近更新 更多