jQuery 中的 HTML 表格排序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17192669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:37:29  来源:igfitidea点击:

HTML Table Sorting in jQuery

jqueryhtml-table

提问by Waqas Zahoor

I have simple HTML Table, I need to add sorting and grouping on every columns in jQuery.

我有简单的 HTML 表,我需要在 jQuery 的每一列上添加排序和分组。

<table cellspacing='0'>
<thead>
    <tr>
        <th>Task Details</th>
        <th>Progress</th>
        <th>Vital Task</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>Create pretty table design</td>
        <td>100%</td>
        <td>Yes</td>
    </tr>

</tbody>

采纳答案by Filippos Karapetis

There are various plugins to perform this using jQuery. The most known one is jQuery tablesorter:

有各种插件可以使用 jQuery 执行此操作。最著名的是jQuery tablesorter:

http://tablesorter.com/docs/

http://tablesorter.com/docs/

There are loads of such plugins here, pick the one you like most:

这里有很多这样的插件,选择你最喜欢的一个:

http://www.tripwiremagazine.com/2013/06/jquery-filter-sort-plugins.html

http://www.tripwiremagazine.com/2013/06/jquery-filter-sort-plugins.html

回答by Claudio Redi

You could use tablesorterfor this. It's very simple to use.

您可以为此使用tablesorter。使用起来非常简单。

$(document).ready(function() { 
   $("#myTable").tablesorter();  // <-- 'myTable' is the id of your table    
}); 

Hereyou could check a working demo

在这里你可以检查一个工作演示

回答by isJustMe

I suggest using datatables, you use it like this:

我建议使用datatables,你可以这样使用:

$(document).ready(function(){
    $('#example').dataTable();
});

回答by DhruvPathak

Do not reinvent the wheel. Use jquery tablesorterplugin.

不要重新发明轮子。使用jquery tablesorter插件。