Java 在 JSP 中为表格添加排序功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18293155/
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-12 00:09:57  来源:igfitidea点击:

Add sorting capabilities to table in JSP

javajsp

提问by danieln

Is there a way to make a table in JSP sortable?

有没有办法使 JSP 中的表格可排序?

I couldn't find anything on the net regarding this, so I assume it's impossible, but I thought I would try here.

我在网上找不到任何关于此的信息,所以我认为这是不可能的,但我想我会在这里尝试。

采纳答案by heretolearn

You can use this piece of codefor adding sorting capabilities to your tables in JSP. You would just need to include this JavaScript file to your jsp page and follow the instructions.

您可以使用这段代码为 JSP 中的表添加排序功能。您只需要将此 JavaScript 文件包含到您的 jsp 页面并按照说明进行操作。

It is simple to implement and is under X11 licence, which basically means you can do what you want with it, including using it at work, in a commercial setting or product, or in open source projects.

它易于实施且受 X11 许可,这基本上意味着您可以用它做任何想做的事情,包括在工作、商业环境或产品或开源项目中使用它。

Click here for more details

点击这里了解更多详情

Hope this helps !!

希望这可以帮助 !!

Thanks to Stuart Langridge !!!

感谢斯图尔特·兰格里奇!!!

回答by Carlos Gavidia-Calderon

DisplayTagis a nice library that can handle that kind of stuff for you, and also includes some other neat functionalities like sorting and data export.

DisplayTag是一个很好的库,可以为您处理这类事情,还包括一些其他简洁的功能,如排序和数据导出。

Installingthe library only consists in dropping a few jars. After display tag is ready, making a sortable table is done through some custom tags provided by the library. This sample code is from DisplayTag documentation:

安装库只包括删除几个 jars。显示标签准备好后,通过库提供的一些自定义标签来制作一个可排序的表格。此示例代码来自DisplayTag 文档

<display:table name="testList" sort="external" defaultsort="1" id="element">
  <display:column property="id" title="ID" sortable="true" sortName="id" />
  <display:column property="firstName" sortable="true" sortName="firstName" title="First Name" />
  <display:column property="lastName" sortable="true" sortName="lastName" title="Last Name" />
  <display:column property="address" sortable="true" sortName="address" title="Email Address"/>
</display:table>