Reordering of column data in mysql

后端 未结 4 1464
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-07 11:47

I have a table like so:

categoryID      categoryName
----------------------------
     1            A
     2            B
     3            C
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 12:29

    You could keep order as integer and renumber all the items between a drag's source index and destination index because they can't drag that far, especially as only 20 odd categories. Mulit-item drags make this more complicated however.

    Float is easier, but each time they move you find the middle you could very quickly run out of precission, I would write a test for this to check it doesn't finally give up working if you keep moving the 3rd item to the 2nd pos over and over.

    Example:

    1,2,3
    Move 3rd to 2nd
    1,1.5,2
    Move 3rd to 2nd
    1,1.25,1.5
    Move 3rd to 2nd
    1,1.125,1.25
    

    Do that in an excel spread sheet and you'll find the number becomes too small for floats to deal with in about 30 iterations.

提交回复
热议问题