Sorting Table Rows By Dates in Javascript

Hi Experts,

I have a requirement of sorting the rows of a html table.

Here the rows  of the table are copied into an actual array to maintain a copy.
The original html table consists of the foll rows saved in the index 0,1,2,3
09/09/2012 Gaara
09/08/2012 Vegeta
09/07/2012 Nappa
09/06/2012 Goku


Then i parse only the date value from the row which is in mm/dd/yyyy and also i get the actual row number in which the date occurs which is in the form 0,1,2,3,.. and so on.
The format is as follows:
09/09/2012~0
09/08/2012~1
09/07/2012~2
09/06/2012~4

What i need is that is the actual sorted row number like which in the above case is 3,2,1,0 so that i can arrange the rows using the actual copy saved before.

If i get this order then i can arrange the original data as follows
09/06/2012 Goku
09/07/2012 Nappa
09/08/2012 Vegeta
09/09/2012 Gaara

Please help...
gaugetaAsked:
Who is Participating?
 
lwadwellCommented:
Existing javascript packages that add the sorting capability to html tables include (not an exhaustive list by any means)
Sorttable: http://www.kryogenix.org/code/browser/sorttable/
Tablesorter: http://tablesorter.com/docs/
Standardista Table Sorter: http://www.workingwith.me.uk/articles/scripting/standardista_table_sorting.
0
 
lwadwellCommented:
Are you wanting the table to be sortable or to be displayed in a fixed order?

If a fixed order ... how is the table built?  Is it sourced from a database via a query or what?

If you want the table sortable ... there are various packages available than can do that.
0
 
Julian HansenCommented:
How are you storing your sorted values you give the example

09/09/2012~0

This this mean you have an array of dates where the ~0 indicates the index of the array?

And what you want is after you have sorted the array how to get the original index of the source row?

How are you sorting the array of dates - can you not make that an array of objects or arrays with each element having two values - date and original row number?
0
 
gaugetaAuthor Commented:
@lwadwell & @julianH:Thanks for replying.

@lwadwell:After the table is displayed after queryring the db I want the ros of the table to be flexible such that the rows of the table should be sortable by different columns of the table in this case date.

@julianH:09/09/2012~0
This represents the date vale and the row index which was stored earlier for repopulating after sorting after we get the sort order.
While comparision I do not consider ~0 part by taking the value using substring function and later arrange the ascening or descending aray by using the part after ~ symbol.

BTW how do we do the same comparision of times in the format hh:mm:ss and how is it different from the date comparison.
0
 
Julian HansenCommented:
@julianH:09/09/2012~0
This represents the date vale and the row index which was stored earlier for repopulating after sorting after we get the sort order.

If it is part of the string then why not just chop of the last bit of the string to get the original index?

Not seeing the problem here.

And as lwadwell says - there are many sorting tools out there. Personally I prefer to sort server side than send hundreds of records to the client - but that's a personal call.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.