'Drag-n-drop' - List iteration and refresh

Hi,

I'm using a 'Drag-n-drop SorteableList' app to enhance a list. The goal is to reorder the list using a drag and drop functionality and have this new list registered in the database. The entity is 'FAQ' and the attribute by which the list is ordered is called 'rank'.

Step 1, drag a row to its new position

Step 2, have a 'for each' run through the list and assigning to each record, its new rank value:

FaqTable.List.Current.FAQ.Rank = FaqTable.List.Current RowNumber +1

Step 3, use the CreateOrUpdate to update in the database each record with its new rank value

Step 4, display the already ordered list with the corresponding rank values in the logic of Step 2

The problem is that the 'for each' starts iterating with the old list. Say... I drag row 3 to row 1 and he starts by the initial record in row 1.

Also, after refreshing, the list displayed remains initial.

Solution

Hi João,


It is useful to take a look at the demo Module on how to use this web block: demo module in Forge

I don't think dragging items makes any modifications on the data of the screen, the Sortable webblock sends a message with the VarChanged event, that you can use in your event handler to know what the changed order is.

In order to do that :

1) you must attach an attribute to each row of your TableRecords, uniquely identifying that item (so that could be the id from the entity)  This is done by setting a Extended Property at the row level. 

The value (i found with some trial and error) must have some text ending with underscore, and then the id.



2) The name of the attribute must match the properties of the Sortable webblock (in my case 'itemnr')


3) while debugging, this is what the 'Message' parameter looks like after dragging the first below the third

So, you'll need to do some string manipulation to extract those 4 id's from that message, and then update them accordingly.


Good luck,

Dorine

Solution

Thanks for the 'Message' tip as well as finding the Extended Property correct use. 

I used a String_Split Server Action toghether with a 'For Each' to cut through the message and extract the values.

The RefreshSortable action comes after the cycle is finished.