Table design to support move row up/move row down operations

  • In the UI my client wants a list of rows each with a move up and move down button. I have a free hand in designing the table to support it, but I am looking for ideas.

    So far I am thinking of adding a sequence column. That bit is easy. The interesting bit is choosing a datatype for it and operations to manipulate it.

    choice 1 - int

    To move a row now would require two updates. To move up row n requires updating the sequence number in row n and row n-1.

    To insert a new row requires re-numbering all the following rows.

    choice 2 - float/real

    to move a row only requires updating one row. To move row n up I would calculate a new sequence number as (seq(row n-1)+seq(row n-2))/2. This is fine until we run into more fractional digits than float/real can hold.

    To insert a new row requires much the same calculation

    I'm sure I cannot be the first person to want this. Is there some standard approach I am missing?

  • richard-674310 (4/28/2011)


    ... Is there some standard approach I am missing?

    This has been discussed on the forum before, I'll try to find the thread.


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • Thank you. I tried several searches before posting. Clearly I failed to hit on the magic search sauce.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply