简体   繁体   English

如何在没有库的情况下使用Java排序表?

[英]How to sort a a table with Javascript without library?

There is two main aims: 有两个主要目标:

  1. Sort table of data using javascript without libraries such as jquery, so pure javascript. 使用没有库(例如jquery)的javascript来对数据表进行排序,因此是纯javascript。

  2. Sort/group rows together based on class/id (like css). 根据类/ id(如css)对行进行排序/分组。

I thought maybe getElementById could be useful, but don't know enough javascript to investigate properly. 我以为getElementById可能有用,但没有足够的JavaScript来进行适当的调查。

A table's rows can be found in the rows[] array of said table. 可以在该表的rows rows[]数组中找到表的行。

You can create an array containing those rows. 您可以创建一个包含这些行的数组。

You can then .sort() the array based on a callback function that looks up certain info, in the form 然后,您可以根据查询特定信息的回调函数对数组进行.sort() ,格式为
.sort(function(a,b) { /* return -1 if a comes before b or 1 if b comes before a */ })

If you iterate over the array and appendChild the rows to the table they are in, the result is a sorted table. 如果对数组进行迭代,然后将子行中的行appendChild到子表中,则结果是已排序的表。

If you have problems with the actual code, please post what you have so far and we can help more specifically ;) 如果您对实际代码有疑问,请发布您到目前为止的内容,我们会为您提供具体帮助;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM