【问题标题】:sort a table in jsp using jquery plugin使用 jquery 插件对 jsp 中的表进行排序
【发布时间】:2014-12-02 03:34:29
【问题描述】:

我正在尝试在 jsp 中对表格进行排序。我使用了一个名为 tableSorter 的 jquery 插件来对我的表进行排序,但我没有任何运气。这是我的代码。我不确定我在哪里遗漏了一些东西。我正在从 MYSQL 数据库中填充此表。

这是我用来在 jsp 中对表格进行排序的表格排序器功能。

    <script type="text/javascript" src="js/jquery-ui-min.js"></script>
    <script type="text/javascript" src="js/jquery.tinysort.min.js"></script>

var aAsc = [];
function sortTable(nr) {
aAsc[nr] = aAsc[nr]=='asc'?'desc':'asc';
$('#records>tbody>tr').tsort('td:eq('+nr+')[abbr]',{order:aAsc[nr]});
}

<table ID="records" class="results" border="1" cellspacing="0">
<thead>
<tr>
<th><a href="javascript:sortTable(0)" style=" color: #ffffff; text-decoration: underline; ">ID</a></th>
<th>Name</th>
<th>Date</th>
</tr>
</thead>

 <logic:notEmpty property="results" name="finalResults" scope="page">
 <logic:iterate id="i" indexId="count" property="results" name="finalResults" scope="page">

  <%-- Logic for formatting the data from DB goes here--%>
 </logic:iterate>
 </logic:notEmpty>

我在这里使用 href 对数据进行排序。但是当我点击它时,href 没有做任何事情。我错过了什么吗?

【问题讨论】:

  • 表格中没有上下箭头(如docs demo)还是什么?
  • 我正在使用 href 对数据进行排序。单击它后,列排序。我想对各个列进行排序,而不是对整个表本身进行排序。

标签: javascript jquery mysql jsp sorting


【解决方案1】:

类应该是tablesorter

like : table ID="records" class="tablesorter" border="1" cellspacing="0"

试试这个::

我做了一个例子,请看这个链接,我在这里使用_jquery.tablesorter.min.js 如果这有帮助,请告诉我。 tableSorter Example

【讨论】:

  • 我尝试使用 tablesorter 上课。它没有帮助。
  • 我已经更新了示例。请检查并告诉我是否有帮助
  • 是的,它奏效了。但我只能对第一页中的数据进行排序。我有大约 20 页,如何在这里使用分页对数据进行排序。
  • 在这种情况下,您可以在服务器端执行此操作,例如在 namedateId 中添加 Order by你选择查询。 OR 以 JSON 格式获取整个数据并在加载期间显示 1-20 条记录,然后根据 Next click event 显示 20-40 条记录,您可以使用它来排序使用上述示例的整个列。我建议您使用用户服务器端排序,因为在客户端使用 JSON 会花费大量时间
猜你喜欢
  • 1970-01-01
  • 2013-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 2012-05-07
相关资源
最近更新 更多