client side sorting of datagrid items

A

Andrea Williams

Does anyone know if there's code out there to manage client-side sorting of
datagrid items? I'd like to be able to fill a datagrid with records from
the database, then allow the user to put the records in their preferred
order. So I envision two buttons for each row that are for up and down and
when the up button is pressed, the selected row's data is traded with the
row above WITHOUT a refresh of the page.

I don't know even where to start in building such a thing or if it's
possible with client-side code.

Thanks in advance for your ideas!
Andrea
 
A

Andrea Williams

Sorry, it looks like I already asked this question a while ago, but if
anyone has anything new to add, I would be greatful.

Andrea
 
E

Eliyahu Goldin

Andrea,

What you need is not sorting, rather swapping table rows. It can be easily
done in javascript using DHTML table object representing your grid. The big
question is if you need to communicate the new order to the server. That is
a really tricky task.

Just to swap table lines you can do the following:

For every grid data cell setup client-side onclick event that will save the
key value of the row clicked.

Your grid is a DHTML table objects. It has a collection of rows.

In the up button click handler:

In the collection of rows find the row with saved key value. Cell values are
kept in the collection of cells for every row.

Swap cells of the found row with their counterparts in the previous row. The
order of the rows is just their index in the rows collection of the table
object.

Eliyahu
 
A

Andrea Williams

Any ideas on saving the order back to the database. I have a field called
ORDINAL that let's me place them in a particular order.

Andrea
 
E

Eliyahu Goldin

First what comes in my mind is to make on client side a string of pairs
key-ordinal for every row. Have a hidden field on the form and set it to
this string on form submitting. On the server side parse the string and
update a database record for every key with corresponding ordinal.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top