java 使用 displaytag JSP 选项卡库对 HTML 表进行排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/267071/
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
sorting HTML tables with displaytag JSP tab library
提问by Dónal
I'm using the JSP displaytagtag lib to create HTML tables. I'd like the user to able to click on a column header in order to sort the data. My JSP code is shown below:
我正在使用 JSP displaytag标记库来创建 HTML 表。我希望用户能够单击列标题以对数据进行排序。我的 JSP 代码如下所示:
<display:table name="tableData" id="stat" sort="page">
<display:column property="name" title="Name" sortable="true"/>
<display:column property="age" title="Age" sortable="true"/>
</display:table>
I thought this would cause the data to be sorted on the client-side (in JavaScript), but what it actually does is create a broken hyperlink on the column header back to the server.
我认为这会导致数据在客户端(在 JavaScript 中)进行排序,但它实际上做的是在列标题上创建一个返回服务器的断开的超链接。
Is it possible to use displaytag to sort data on the client-side? If so, how?
是否可以使用 displaytag 在客户端对数据进行排序?如果是这样,如何?
Cheers, Don
干杯,唐
回答by MetroidFan2002
As far as I know, this is not possible. JQuery's tablesorter may work for the small tables that it uses for its examples, but most tables have to come from an actual database. This hit is far too great to simply retrieve all the data before returning to the client with this information, and then allowing it to be sorted.
据我所知,这是不可能的。JQuery 的 tablesorter 可能适用于它用于示例的小表,但大多数表必须来自实际数据库。这个命中太大了,不能简单地检索所有数据,然后将这些信息返回给客户端,然后允许对其进行排序。
Displaytag has a "requestURI" element for the tag that allows its requests to go to your configured url-handler.
Displaytag 具有用于标记的“requestURI”元素,允许其请求转到您配置的 url 处理程序。
So, if you use this:
所以,如果你使用这个:
<display:table requestURI="yourUrlMappedController.yourExtension" ...>
This will allow for the stopgap solution of retrieving the data again from your controller.
这将允许重新从控制器检索数据的权宜之计解决方案。
Ultimately, though, you'll want to eventually work out a strategy that uses the displaytag sorting parameters to use as options in your "order by" clause and page the data from the database instead of pulling it all at once. This is a tricky thing to do, but the upfront effort can be very rewarding in terms of performance.
但是,最终,您将希望最终制定出一种策略,该策略使用 displaytag 排序参数作为“order by”子句中的选项,并从数据库中分页数据,而不是一次拉取所有数据。这是一件棘手的事情,但前期的努力在性能方面是非常有益的。
The displaytag site has three things you should always check for reference, just as an aside. The Tag Reference, the Configuration Guideand, of course, their (downloadable) Live Examples.
displaytag 网站有三件事你应该经常检查以供参考,顺便说一句。该标签参考的配置指南,当然,他们(下载)活生生的实例。
回答by Josh
Take a look at using jqueryand its excellent tablesorterAPI. This will let you sort the table on the client side using Javascript.
看看使用jquery及其出色的tablesorterAPI。这将允许您使用 Javascript 在客户端对表格进行排序。

