[英]sort a table based on the column values
I want to sort a table when some button is clicked. 我想在单击某些按钮时对表格进行排序。 If the button with id "easy" is clicked I want to sort by easy levels, if the button with id hard is clicked I want to sort by hard levels, in a descending order.
如果单击id为“ easy”的按钮,我想按简单级别排序,如果单击id为hard的按钮,我想按硬级别排序,按照降序排列。
Im trying to do this for the easy button case and I already have the values in a array, but now Im not seeing how to sort this so the table can be sorted based on the easy values on the column "EasyLevels". 我正在尝试针对简单按钮情况执行此操作,并且我已经在数组中包含了值,但是现在我看不到如何对其进行排序,因此可以基于列“ EasyLevels”上的简单值对表进行排序。 Do you have some idea to help?
您有什么想法要帮忙吗?
$("#easy").each(function() {
if ($.inArray($(this).text(), arr) == -1)
arr.push($(this).text());
alert($(this).text());
});
I have a table in this format: 我有这种格式的表:
ID | GameName | EasyLevels | HardLevels | TotalLevels
1 Stakeboard 32 28 60
....
The html is like below, I dont have any class or id in any <td>
. 该html如下所示,我在任何
<td>
都没有任何类或ID。
<button id="easy">Sort By Easy Levels</button>
<button id="hard">Sort By Hard Levels</button>
<button id="total">Sort By Total Levels</button>
<table>
<th>GameId</th>
<th>GameName</th>
<th>EasyLevels</th>
<th>HardLevels</th>
<th>TotalLevels</th>
<tr>
<td>Game Id</td>
<td>Game Title 1</td>
<td class="easy">12</td>
<td class="hard">30</td>
<td class="all">42</td>
</tr>
<tr>
<td>Game Title 2</td>
<td class="easy">10</td>
<td class="hard">26</td>
<td class="total">36</td>
</tr>
....
</table>
You can achieve this using tablesorter jquery plugin: 您可以使用tablesorter jquery插件实现此目的:
$(document).ready(function()
{
$("#myTable").tablesorter();
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.