ng-sortable How to get the list id while item is reordered

2k Views Asked by At

I am using https://github.com/a5hik/ng-sortable to reorder a list using drag and drop.

I am stuck at getting the list id when i move an item between two list. I want to know from which list the drag started and to which it was dropped.

<div id="list1" class="sortable-row" as-sortable="sortableOptions" 
    ng-model="itemsList.items1">
    <div ng-repeat="item in itemsList.items1" as-sortable-item>
        <div as-sortable-item-handle>{{item.Label}}</div>
    </div>
</div>

In the following itemMoved() method i want to get the list id

$scope.sortableOptions = {
    containment: '#sortable-container',
    itemMoved: function (event) {
        console.log("itemMoved()");
        console.dir(event);

        // Identify the list on which order changed

        // Get the last and new position


        // Update card position

    }
};

How do i identify the list on which drag started and on which drop was made.

Here is the plnkr for the same

1

There are 1 best solutions below

2
On

I debugged this little more. Found the id using the following:

console.log('From: ' + event.source.sortableScope.element[0].id);
console.log('To: ' + event.dest.sortableScope.element[0].id);

I hope this helps someone.

Updated the plnkr also for the same.

http://plnkr.co/edit/o0FJt4?p=preview