我正在用 Perl 编写 Multimarkdown 来创建 HTML 表。
我想知道是否有一种简单的方法可以使表格动态化,即允许查看者通过单击列标题对其进行排序,甚至通过输入简单的规则来过滤记录。
我真的不懂 HTML。我用 Perl 编码,只生成 HTML(实际上,Multimarkdown 转换为 HTML)以很好地输出一些数据。我提到这一点是因为我确信有多种方法可以创建漂亮的动态表格,但我真的在寻找一种简单的方法。
I'm writing Multimarkdown from Perl to create an HTML table.
I wonder if there's a simple way to make the table dynamic , that is, allow the viewer sort it by clicking on a column header, or even filter records by entering a simple rule.
I do not really know HTML. I'm coding in Perl and only generate HTML (actually, Multimarkdown converted to HTML) to nicely output some data. I mention this since I'm sure there are various ways to create beautiful, dynamic tables, but I'm really looking for a simple one.
发布评论
评论(4)
简单方法是使用已经支持此类功能的工具包/库。
(在 Google 上快速搜索“排序 javascript 表”来自 JavaScript 工具箱的排序/过滤表格, 使用 JavaScript 对 HTML 表进行排序(更多示例) 和 jQuery 插件:Tablesorter 2.0。)
AJAX 是一种可用于动态获取数据的机制 - 但是,如果所有数据已存在于表中和/或表不需要分页,则这太过分了。这两种方法都需要启用客户端 JavaScript。 (非客户端替代方案是回发并让服务器完成工作并生成新的 HTML。但这就是 Web 一点点哦:-)
CSS(层叠样式表) 仅用于应用颜色、背景图像、字体或边框等样式(CSS 选择器可以基于 CSS 类工作通常在 HTML 元素 class 属性中提供。文档只是简单地说明一些预定义的 CSS 类名称是由 JavaScript 动态添加的,因此。可以轻松地“选择”样式 - 例如,将排序后的列变成石灰绿色)。 CSS 本身无法控制排序或过滤。
Daxim 建议 Stuart Langridge 的排序表 在以下问题中进行了讨论:
如何使用 Perl 与表头关联的超链接中的查询字符串进行客户端排序?(如果此编辑有用,请在那里投票 daxim :-)
快乐编码。
The simple way is to use a toolkit/library that already supports such features.
(A quick google search for "sorting javascript table" turned up Table with sorting/filtering from JavaScript Toolbox, Sorting HTML Tables using JavaScript (more of example) and jQuery plugin: Tablesorter 2.0.)
AJAX is one mechanism that can be used to fetch data dynamically -- however, if all the data is already present in the table and/or the table doesn't need paging, then it's overkill. Both of these methods require that client-side JavaScript is enabled. (The non-client side alternative would be to post-back and have the server do the work and generate new HTML. But that's so Web one-point-oh :-)
CSS (Cascading Style Sheets) is just for applying styles such as colors, background image, fonts or borders, etc (CSS selectors can work based on CSS classes which are often supplied in the HTML element class attribute. The documentation is simply stating that some pre-defined CSS class names are dynamically added -- by the JavaScript -- and thus can be "selected" upon easily for styling - for example, turning the sorted column lime green). CSS itself, however, can't control the sorting or filtering.
Daxim suggested Stuart Langridge's sorttable which is discussed in the following SO question:
how to do client side sorting using querystring in hyperlink associated with the table header using Perl? (Go upvote daxim there if this edit was useful :-)
Happy coding.
Yahoo YUI 的数据表控件具有内置的列排序功能。
YUI 有大量的 js 函数,您可以直接调用和使用。
Yahoo YUI's datatable control has built-in column sorting.
YUI has tons of js functions you can just call and use.
我使用了下面的代码:
I used the code below:
JQuery 是一个 Javascript 库,可让您执行各种简洁的前端操作,包括表排序。使用起来还不错(有点像 php),而且您不必了解太多关于 html/css 的知识(尽管这没什么坏处)。
http://jquery.com/
JQuery is a Javascript library that lets you do all sorts of neat front-end stuff, including table sorting. It's not bad to work with (it's sort of like php) and you don't have to know much about html/css (though that never hurts).
http://jquery.com/