Sort by draggingAlgorithm
When we do some systems, we need users to sort products and categories.
In this case, we need to add an attribute named displayorder to the object.
To increase and decrease, you only need to change the two displayorders.
But if you drag it, It's not a simple exchange. Instead, you need to insert displayorder to the front.
For example, we have
Name displayorder
A 1
B 2
C 3
D 4
E 5
F 6
G 7
Before Pulling g to C, we must set displayorder of G to C.
Then, set C to D, and D to E, and E to F to G.
However, such efficiency is relatively poor. Especially in SQL, it may be troublesome to write this statement.
Because displayorder is at least one difference, we can implement it in a simpler way.
It is to add all displayorder + 1 after C and it, but this algorithm does not seem to be the best.
If it is a relatively long-distance drag, we have to change many items.
A better way is that the displayorder difference value is not 1. In this way, the displayorder of G can be set to C to some extent. C + 1 won't repeat D. To reduce updates.