The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Sorting the table contents using Javascript

Hi all,

I am working on a application similar to the Adobe's Flex store. Everything is working as intended. The main stumbling block is with the sorting of the products by brand name, by price etc. I am using the concept of table sort. But with this i am able to sort the rows only (not all the products are getting sorted), i.e it is comparing first product of each row and carrying out the sort operation. I need all the products to be sorted depending on the sort criteria.

One concept i am trying to go with is the populating an temporary array which stores the products, and i am trying to sort this array and display the contents of the sorted array. I am not getting this to work.

these scripts sort a table by rows (i.e they compare two successive rows).
My aim is to sort randomly arranged products (say in a table of 4X4) according to their price, or some other criteria. (Reference Adobe's flex store, where in u can select a criteria to sort the products currently displayed.)

Well, I'm assuming that you have put the product info into an array or a multi-dimensional array. Depending on the criteria, you're going to have to bubble sort the array by comparing row against each other, moving data around and then loop over the array enough times to sort everything. Does that make sense?

JavaScript arrays have a sort() method which can use a user-defined function to derive the sort values. I'm not really clear on your situation, but if you are using XML it should be possible to directly populate an array with the objects in question and sort, then use the DOM to display the result.