Jump to content

Change Order Of Displayed Items


son
 Share

Recommended Posts

I have developed a basic product catalogue. The order of products on website overview page should be changeable from product admin area. How do you create an option in admin area to change the order? For example via select with arrow up and down which brings item one up or one down. What would be the term for such a thing?Son

Link to comment
Share on other sites

Ordering. You need a database field to hold the numeric order of each item that you update whenever you change the order of something.
When I insert a new product the item gets the same number as product_id (which I auto-increment). Got this. But then on page where all items are displayed in current order how can I change this order? If for example the up arrow is pressed then the item gets the order number of previous item and previous item gets the order number of selected item? Or how would you do this?Son
Link to comment
Share on other sites

If you have a button that moves a single item up or down, yeah, you would just switch the numbers for those two. If you want to send an item to the top or bottom, or move more than one at a time, or drag and drop, it's a little more complex. Nothing that can't be worked out by just drawing it out on paper though.It's best not to make the display order an autonumber or whatever else. They need to be consecutive. When you add a new item, if you want to add it to the end, just get the current max display order and add one to it for the new item. Or, you could insert it in the middle somewhere and renumber the items after it.

Link to comment
Share on other sites

If you have a button that moves a single item up or down, yeah, you would just switch the numbers for those two. If you want to send an item to the top or bottom, or move more than one at a time, or drag and drop, it's a little more complex. Nothing that can't be worked out by just drawing it out on paper though.It's best not to make the display order an autonumber or whatever else. They need to be consecutive. When you add a new item, if you want to add it to the end, just get the current max display order and add one to it for the new item. Or, you could insert it in the middle somewhere and renumber the items after it.
Drag and drop would be marvellous. Does this have a special name, so I can search for help with this? Son
Link to comment
Share on other sites

It's just drag and drop reordering. I've always used the ExtJS library to do drag and drop, where it has a drop event so that I can determine where the item started and where it got moved to, or if it's a tree structure which parent it got moved under.

Link to comment
Share on other sites

It's just drag and drop reordering. I've always used the ExtJS library to do drag and drop, where it has a drop event so that I can determine where the item started and where it got moved to, or if it's a tree structure which parent it got moved under.
So, this is done with Javascript then... I will check for tutorials and see if I get my head around this. As for a simple move one up or down plus move to top and bottom would that be done with JavaScript or can this be done with pure PHP? Son
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...