• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Trouble getting an editable ordered list working...

Furor

Golden Member
I have this html form which has a number of items in which you can change the order - from 1 to any number
The order should always be 1,2,3,4,5,6,7, etc..but I am having a problem figuring out how to maintain that data when the order is being edited.

See the example below..the first line is the original data, the second line is the new data
1 -> 2
2 -> 1
3 -> 3
4 -> 5
5 -> 4

Above, it is pretty simple, I can just re-order based on the input, however it gets more difficult if something else is entered.

1 -> 2
2 -> 1
3 -> 3
4 -> 5
5 -> 1

Above, I need to fix it so either the original 2, or 5 is now 1, then the next is 2, and then make sure there is a 3,4, and 5.

Now it gets harder..

1 -> 10
2 -> 4
3 -> 3
4 -> 5
5 -> 5

This would have to be again, fixed so that 3 now becomes 1, 2 becomes 2, 4 or 5 becomes 3, and 1 becomes 5.

This is probably getting confusing...anyway, unfortunately I can't display any type of error message to the user, I just have to make sure the order stays starting at 1, and is sequential, with no duplicates, all the way to however many items are in the list. I've spent about an hour trying different methods to get this to work but haven't been successful. Anyone have any ideas?
 
You're going to have to be a little more specific about what you're trying to accomplish. Are you saying that you have to allow the user to set three items to postion "1" if they want to, and then correct it on the server? If so, is there some criteria you would use to re-order them, or is it arbitrary?

The surest solution is to not let the user make that kind of choice to begin with. One way to avoid it without doing any scripting on the client is to have a single selection listbox with a button for "move selected up" and another for "move selected down."
 
Yes, the user will probably not purposely set three items to "1", but they may set the very bottom entry to "1" while the very top entry is already "1" and it has to be corrected on the server. The only criteria to re-order them is what they submitted. The lowest number needs to be set to 1 and the next lowest needs to be 2, etc...

I have tried the move up / move down option, but there are a couple of problems that prevent me from using it:
1. There is other data that needs to be shown next to each item.
2. The page needs to update all entries with a single click.
3. If an item from order 33 needs to be moved to order 12, there is no way other than pushing move down tons of times.

If it's still not clear, I will try to get a test page up tomorrow at work.
 
Originally posted by: Furor
If it's still not clear, I will try to get a test page up tomorrow at work.

Would probably help...

Also, what language are you using on the server? Are you using JavaScript on the client side?

 
ColdFusion on the server side, but could use sample code from most languages if someone has any.
Not using any javascript for this particular page other than some built in ajax.

Edit: I'm not really looking for code (of course, it would definitely help) but more so looking for ideas on how to get this working...I am thinking I will need 2 or 3 loops..

1 loop through all of the numbers - 1,2,3,4,5,6....
1 loop through all of the form fields to get the values submitted..
maybe create an array of the values...
1 loop that contains the other loops to do the processing
 
Here is a slightly modified version of the page I am working on:

removed link

The left column is the ordered list - it will update if you click the Pos button above it. It just won't update correctly because that's what I am trying to get working.
 
Well, I'd still go with the "up/down buttons" idea, but use a gridview and sort the rows on the server.
 
I don't know anything about ColdFusion, but there are data structures in .NET like SortedDictionary<TKey, TValue> - TKey is the key by which you retrieve data, and TValue is actual content associated with the key. With some conventional thought, this structure can be expanded into a "deeper" object, meaning your TValue could be any object as long as the keys are unique. You can even write a custom comparer for how keys are compared. I believe if you have such a programming model at offer in ColdFusion, this would be a straight-forward task. I guess I mention this, because depending on the functionality, making an AJAX call to the server and getting an updated ordered list would be trivial.

It would be tedious in JavaScipt.

From the looks of it, I don't see why you would need to maintain the old values when it is your current state that determines the order in the Edit mode.
 
Back
Top