Jump to content
Greg Hains

Re-ordering list entries

Recommended Posts

Hi.

(If somebody feels this question needs to be moved to another section, please advise - I couldn't make it "fit" anywhere else)

I have a table with several items in it.  One of the fields is "order_num" (a number), the other field is text. What I am looking to do is be able to reorder that list based on the number - which can change. But wait for it...  :)

I want to be able to reorder that list with either a increment and decrement button, where clicking them would either increase the order_num number or decrease its position in the list. A script trigger could then re-sort that list based on the new numbers in that list.  What I am not sure how to do is increment or decrement the number but not make it the same as any other number.
For example:
If I have three records where the numbers (in order are "1", "2" and "3"). If I wanted to move the second record to the top of the (ordered) list by making it "1", it would then have the same value as the first record (1,1,3).  I would like to do something like decrement every number below it so that there were only unique numbers and the list could be re-sorted.
This seems clumsy to me, so figure there must be a more elegant solution.

Ideally, I was hoping to have it so I could either use the increment [in list] or decrement in list, or be able to drag the items to a new location in the list - like "between" others. I've sort of had this working with container fields, but never in list re-ordering.

Has anybody got any ideas how I could achieve this please?  Any suggestions welcome.

Many thanks in advance.
Greg 

 

 

Share this post


Link to post
Share on other sites

A few random notes:

1. You can move a record up/down by exchanging its order_num values with the preceding/following record.

2. You can move a record to the top of the list by setting its order_num value to the minimum of order_num - 1 (in your example, that would be 0). If necessary, you can use the Replace Field Contents step to renumber the entire found set at the end.

3. Re drag and drop, see if these can help:
https://fmforums.com/topic/93510-containers-drag-and-drop-script-triggers/?tab=comments#comment-427732
https://fmforums.com/topic/67781-script-triggers-and-drag-drop-incompatible/?tab=comments#comment-322507

4. Keep in mind that re-ordering records manually can be problematic in a multi-user scenario.

 

 

Share this post


Link to post
Share on other sites

Hi Comment.

Thank you again. :)

At first I was just going to change the order_num value of the current record (being moved) to less then that of the number below it - but swapping it would be cleaner, so I will do that.  it is multi-user environment so I will have to test it thoroughly to see how it goes. 'What could possibly go wrong?!"  

Cheers,
Greg
 

Share this post


Link to post
Share on other sites
34 minutes ago, Greg Hains said:

'What could possibly go wrong?!"  

You ask jokingly, but I will answer in earnest. There are two things that could wrong:

  1. User A arranges records in order A. Then User B rearranges them in order B, thus defeating whatever purpose User A had in mind. User A tries to put them back in order A - to the frustration of UserB. Repeat as necessary.
  2. User A tries to arrange records, but keeps getting errors because other users happen to be editing some of the records being moved.

Those are the pitfalls of re-ordering records by modifying them (plus there is the issue of "last modified" becoming meaningless). There are alternatives, but we don't know if they will fit here because we don't know the purpose of reordering.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi Comment,

Thankyou, and I did not mean to scoff at your advice. I know that such changes would be difficult to manage in a multi-user environment. I really know that a lot COULD go wrong doing this, however, the solution you put forward will work for my purposes.

Cheers.
Greg

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.