使用 displaytag JSP 选项卡库对 HTML 表格进行排序

发布于 2024-07-08 14:38:34 字数 558 浏览 7 评论 0原文

我正在使用 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>

我认为这会导致数据在客户端(在 JavaScript 中)进行排序,但它实际上所做的是在列标题上创建返回到服务器的损坏的超链接。

是否可以在客户端使用displaytag对数据进行排序? 如果是这样,怎么办?

干杯, 大学教师

I'm using the JSP displaytag tag 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:

<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.

Is it possible to use displaytag to sort data on the client-side? If so, how?

Cheers,
Don

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏至、离别 2024-07-15 14:38:34

据我所知,这是不可能的。 JQuery 的表排序器可能适用于其示例中使用的小表,但大多数表必须来自实际数据库。 这种点击量太大,无法在将此信息返回给客户端之前简单地检索所有数据,然后对其进行排序。

Displaytag 的标签有一个“requestURI”元素,允许其请求发送到您配置的 url 处理程序。

因此,如果您使用它:

<display:table requestURI="yourUrlMappedController.yourExtension" ...>

这将允许作为权宜之计再次从控制器检索数据。

但最终,您最终会希望制定出一种策略,使用 displaytag 排序参数作为“order by”子句中的选项,并对数据库中的数据进行分页,而不是一次性提取全部数据。 这是一件棘手的事情,但就性能而言,前期的努力可能会非常有价值。

顺便说一句,displaytag 网站上有三件事您应该经常检查以供参考。 标签参考标签参考 sourceforge.net/11/configuration.html" rel="nofollow noreferrer">配置指南,当然还有他们的(可下载)实例。

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.

Displaytag has a "requestURI" element for the tag that allows its requests to go to your configured url-handler.

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.

The displaytag site has three things you should always check for reference, just as an aside. The Tag Reference, the Configuration Guide and, of course, their (downloadable) Live Examples.

醉酒的小男人 2024-07-15 14:38:34

看看使用 jquery 及其优秀的 tablesorter API。 这将允许您使用 Javascript 在客户端对表进行排序。

Take a look at using jquery and its excellent tablesorter API. This will let you sort the table on the client side using Javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文