我怎样才能使用JavaScript来排序的HTML表格,而无需通过AJAX加载数据? [英] How can I make an HTML table sortable with javascript without loading data via AJAX?
问题描述
如何在不通过AJAX加载数据的情况下使用JavaScript对表进行排序?更具体地说,我正在寻找一个解决方案,它提供了以下内容:
m不寻找:
- 一个解决方案,需要我通过AJAX调用来填充数据。我希望将这个应用于一个项目,该项目有许多普通的旧HTML表格,用于像搜索结果这样的内容,我希望在不重写任何服务器端代码的情况下快速进行排序。
- 寻呼。
- 过滤。
- 指定任意比较逻辑的能力。
我有意忽略我们现在正在开发的特定项目的技术栈,但是如果人们认为这是绝对必要的,那么将包括它。同样,我最感兴趣的解决方案不涉及服务器上的任何内容。有很多用各种语言编写的项目可能会在这方面使用一点爱。
关于堆栈中类似的现有问题溢出
我已经做了一些动作,我能找到的最接近的问题是这一个。然而,我的要求有点不同,所以我决定提出一个新问题。
jquery插件 tablesorter 非常好用。
How can I make a table sortable using javascript without loading data via AJAX? More specifically, I'm looking for a solution that gives me the following:
- Works on a plain old HTML table
- Makes columns sortable using a natural comparison
- Is agnostic of server-side technology (should be portable regardless of whether the tables are being rendered by JSP, PHP, etc)
- Implemented preferably as an extension to JQuery, which I'm already using in the specific project I'd like to immediately apply this to. I'm open to suggestions involving another javascript framework such as YUI, but it will need to play nice with JQuery.
What I'm not looking for:
- A solution which requires me to populate the data via an AJAX call. I'd like to apply this in a project that has a number of plain old HTML tables for things like search results that I'd like to quickly make sortable without rewriting any server-side code.
- Paging.
- Filtering.
- The ability to specify arbitrary comparison logic.
I'm purposefully omitting our technology stack for the specific project I'm working on for now, but will include it if people feel that it is absolutely necessary. Again, I'm most interested in solutions that don't involve anything on the server. There are a ton of projects written in all sorts of languages that could use a little love in this area.
Regarding the issue of similar, existing questions on Stack Overflow
I've done some poking around, and the closest question I can find to mine is this one. My requirements are a little different, however, and so I decided to ask a new question.
The jquery plugin tablesorter works very nicely.
这篇关于我怎样才能使用JavaScript来排序的HTML表格,而无需通过AJAX加载数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!