0

There is two main aims:

  1. Sort table of data using javascript without libraries such as jquery, so pure javascript.

  2. Sort/group rows together based on class/id (like css).

I thought maybe getElementById could be useful, but don't know enough javascript to investigate properly.

1
  • I'm not sure about getElementById, but I would probably start with something like...<script> perhaps. Commented Jun 2, 2013 at 6:31

1 Answer 1

1

A table's rows can be found in the rows[] array of said table.

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

If you have problems with the actual code, please post what you have so far and we can help more specifically ;)

Sign up to request clarification or add additional context in comments.

3 Comments

I don't want to do it in php because I want to put the onus on the visitor browser to conduct the sort rather than process an array on the backend, unless are you talking about javascript?
@Stephen "He" is correct, although thank you for not assuming either way ;)
"This is some pretty basic stuff" ok I feel even dumber than I did before, im sure that was not as intended :) Thanks Kolink, I will do more research ;)..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.