...

View Full Version : Reorder list of data



thewabbit1
06-15-2010, 09:50 AM
Hi there

I am a novice with JavaScript, and I was wondering how I would reorder a list of data. I googled this and found some ways but none of them really applied to me.
I have a database with names of courses (its for a restaurant), they all have an ID which ranges from 1-8 (I only have 8 courses so far). I can add and delete courses from this table but I would like to be able to reorder theses courses, in other words change their ID, without having to go into the database and manually change itself.

Thank you

abduraooft
06-15-2010, 10:01 AM
Could you please post the code that you've done so far?

thewabbit1
06-15-2010, 10:13 AM
I don't actually have any code so far.. I was kinda hoping you could help me out with that....

Philip M
06-15-2010, 11:19 AM
It is not too easy to envisage what you are trying to do. Please give an example of the "before" and "after".

You talk about a database. Surely this should be done server-side?


"This is the worst disaster in California since I was elected." - California Governor Pat Brown, discussing a local flood

thewabbit1
06-15-2010, 11:32 AM
so say I have a list of data in my database that looks like this:

id course
1 c1
2 c2
3 c3
4 c4

then I open up my page and change (which is want i want to do) the order in which they appear. So I drag/move/w.e the entries about so they look like this:

id course
3 c3
2 c2
1 c1
4 c4


I'd now like to be able to add this new order to the database, but change the id of each course so that order will change

id course
1 c3
2 c2
3 c1
4 c4


I hope this helps, im not the best at explaining sometimes =s

Thanks

SB65
06-15-2010, 11:43 AM
I don't think you want to change the ID - you need an additional column in your database table which displays the sort order. As per other posts this is going to need some server side stuff.

However, it's possible to do drag and drop with the aid of jQuery relatively simply , plus some AJAX to update your database - have a look at this (http://www.simonbattersby.com/blog/index.php/drag-and-drop-with-jquery-ui/) - it's for changing the display order of some images - but the idea's the same.

thewabbit1
06-15-2010, 11:50 AM
awesome, thank you for that link, i shall give it a go now :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum