scottdurow / power-drag-drop

MIT License
130 stars 26 forks source link

First drag and drop resets position #80

Open iozm opened 1 month ago

iozm commented 1 month ago

I'm not sure if this is a true issue or maybe just something I am doing wrong.

Scenario: I have 3 drag and drops to manage priority of tasks. The objective is to be able to manage the priority of each task by high, medium, low values but also to track its position and set up a number value for an internal priority within the priority. So I am tracking both position and zoneid. Sorting is set up to follow index.

All three zones are tied to the same collection. On drop event of each zone I check if the item has either changed position OR zone PowerDragDrop_High.CurrentItems, HasMovedPosition = true Or HasMovedZone = true

If true, I update the collection with the zoneid value and the position value.

Issue: The first drag and drop does not register fully in CurrenItems property. However the change is reflected in the collection. Repeating the move makes the changes stick in the CurrentItems property. (i.e. I switch item in position 1 to position 2, the component re-renders the sort how they were before the drop).

drag drop

OnDrop property of master component ForAll( Filter (PowerDragDrop_High.CurrentItems, HasMovedZone Or HasMovedPosition) As HighPriorityItem, Patch( colAIIdeas, LookUp(colAIIdeas, Text(new_aiidearegistryid) = HighPriorityItem.ItemId), { new_ideapriority: HighPriorityItem.Position, new_prioritytext: HighPriorityItem.DropZoneId, Edited: true } ) );

iozm commented 1 month ago

Issue seems to only persist when I track HasMovedPosition . If this value is true, I update the collection with the new position number. Collection gets correctly updated but CurrentItems still does not reflect the change after the first move.

Before first drop: before colbefore

After first drop: after colafter

Passing items in CurrentItems where position has shifted is what seems to replicate my issue. Strangely, if I'm in no way tracking this HasMovedPosition property, the CurrentItems table gets updated appropriately and there is no reset.

iozm commented 1 month ago

I have figured out a workaround.

Instead of using 1 collection I am now using 2, one for the data displayed in component and the other one to handle the actual data updates.

OnVisibleof my screen I load both collections, on drop I only update the one used for data updates and OnHiddenof screen I clear both. (Since I'm only using these collections for this particular screen)

iozm commented 1 month ago

I have figured out a workaround.

Instead of using 1 collection I am now using 2, one for the data displayed in component and the other one to handle the actual data updates.

OnVisibleof my screen I load both collections, on drop I only update the one used for data updates and OnHiddenof screen I clear both. (Since I'm only using these collections for this particular screen)

This now presents an issue on save, somehow its unable to keep track of all the changes I make (both position and zone) so it does not update all the affected rows correctly.

Any advise would be well received.

craigmday commented 1 month ago

I am experiencing the same issue. On my OnDrop event, I am updating my collection to indicate that the item has been moved. I am patching the new position and other details, and the underlying data in the collection is correct. However, like iozm, my tiles keep getting automatically re-sorted after I move them.

Is there some way to prevent any sorting behaviour and let the items stay where they were dropped? This was working previously, but now it is not.

craigmday commented 1 month ago

UPDATE: This behavior seems to be related to the existing number of items in a particular space and whether there are existing items in the slot you drag an item into.

For example, let's say I have items 1, 2 and 3 scheduled for John Smith on Thursday. If I re-order the items within this resource/day slot, there are no issues with sorting. I can also move some or all of the items to a different resource/day slot with no existing items, and there are no issues sorting. E.g., if the original number of items is three, and I only deal with those items, sorting works correctly.

Now, let's say I have Item 4 scheduled for John Smith on Friday. If I move one of the three original items (say, Item 1) to Friday, I am unable to make Item 1 display as the first item of the day slot. It automatically shuffles Item 4 to the top.

It's like the problem occurs if you are mixing items from different originating day slots.

If anyone else has encountered this and has suggestions, please let me know. I can't implement the work-around of using a different collection because I need my moved items to be patched to indicate visually that they have been moved.

iozm commented 1 month ago

UPDATE: This behavior seems to be related to the existing number of items in a particular space and whether there are existing items in the slot you drag an item into.

For example, let's say I have items 1, 2 and 3 scheduled for John Smith on Thursday. If I re-order the items within this resource/day slot, there are no issues with sorting. I can also move some or all of the items to a different resource/day slot with no existing items, and there are no issues sorting. E.g., if the original number of items is three, and I only deal with those items, sorting works correctly.

Now, let's say I have Item 4 scheduled for John Smith on Friday. If I move one of the three original items (say, Item 1) to Friday, I am unable to make Item 1 display as the first item of the day slot. It automatically shuffles Item 4 to the top.

It's like the problem occurs if you are mixing items from different originating day slots.

If anyone else has encountered this and has suggestions, please let me know. I can't implement the work-around of using a different collection because I need my moved items to be patched to indicate visually that they have been moved.

You might need an issue on your own cause this is not the case for this issue, I am having the behavior in both scenarios, only position has changed and both position/zone changed.

craigmday commented 1 month ago

Sorry for all the replies, but I have finally figured out the problem and I think it will help you too.

The order that the fields are listed in the Drag and Drop object field list affect how they are naturally sorted. This behavior seems to override any sorting you add yourself on the data source.

For example, for my unassigned task list, I want the items sorted by the Job Description, and that is finally working after I moved the Job Description field to the top of the list. image

For my tasks on the calendar, I want them sorted by a column called "Call No." which I am using the determine the correct order (position) when saving and reloading. When I move that field to the top of the field list for that Drag and Drop control, it works! image

Now, whenever I move items around in the calendar, it keeps them in the right place because I am patching the "Call No." value in the OnDrop event after each item moves. I hope this works for you too.

iozm commented 1 month ago

Sorry for all the replies, but I have finally figured out the problem and I think it will help you too.

The order that the fields are listed in the Drag and Drop object field list affect how they are naturally sorted. This behavior seems to override any sorting you add yourself on the data source.

For example, for my unassigned task list, I want the items sorted by the Job Description, and that is finally working after I moved the Job Description field to the top of the list. image

For my tasks on the calendar, I want them sorted by a column called "Call No." which I am using the determine the correct order (position) when saving and reloading. When I move that field to the top of the field list for that Drag and Drop control, it works! image

Now, whenever I move items around in the calendar, it keeps them in the right place because I am patching the "Call No." value in the OnDrop event after each item moves. I hope this works for you too.

I will have to try this, unsure if it would be a direct apply. I sort my items by a field not shown in the template.

mattausten commented 1 month ago

Sorry for all the replies, but I have finally figured out the problem and I think it will help you too.

The order that the fields are listed in the Drag and Drop object field list affect how they are naturally sorted. This behavior seems to override any sorting you add yourself on the data source.

For example, for my unassigned task list, I want the items sorted by the Job Description, and that is finally working after I moved the Job Description field to the top of the list. image

For my tasks on the calendar, I want them sorted by a column called "Call No." which I am using the determine the correct order (position) when saving and reloading. When I move that field to the top of the field list for that Drag and Drop control, it works! image

Now, whenever I move items around in the calendar, it keeps them in the right place because I am patching the "Call No." value in the OnDrop event after each item moves. I hope this works for you too.

Nice one! I've been racking my brains all day trying to figure this out!