Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag and drop is picking wrong item to move when the items are externally reordered. #125

Open
vishwajeetv opened this issue Nov 13, 2017 · 1 comment

Comments

@vishwajeetv
Copy link

When the model of the sv-part is externally sorted, (as part of the table, https://github.com/daniel-nagy/md-data-table sorted using table's sort feature), this library is picking a wrong element to move.

The $item in sv-on-sort="dragged($item, $partFrom, $partTo, $indexFrom, $indexTo)" is isn't the item that is being moved.

@vishwajeetv
Copy link
Author

https://stackoverflow.com/questions/47266941/angular-sortable-views-drag-and-drop-is-picking-wrong-item-to-move-when-the-ite

The $item in sv-on-sort="dragged($item, $partFrom, $partTo, $indexFrom, $indexTo)" is isn't the item that is being moved.

Template

<table md-table md-row-select multiple  ng-model="selectedContextContent" md-progress="promise">
    <thead md-head  md-order="tableOrder"  >
    <tr md-row>
        <th ng-show="column.order" md-order-by="{{column.order}}" ng-repeat="column in contentColumns" md-column><span>{{column.title}}</span></th>
    </tr>
    </thead>
    <tbody md-body sv-root sv-part="contentData" sv-on-sort="dragged($item, $partFrom, $partTo, $indexFrom, $indexTo)">
        <tr md-row ng-repeat="content in ContentData | orderBy: tableOrder"
        sv-element="{containment:html,revert:0}">
    </tr>
    </tbody>
</table>

Controller Code

$scope.dragged = function ($item,$partFrom,$partTo,$indexFrom,$indexTo) {

        console.log($item);
        var partToArray = angular.copy($partTo);
        var orderArray = [];

        angular.forEach(partToArray, function (content) {
            orderArray.push(content.displayOrder);
        });

        orderArray.sort(function(a, b){return b-a});

        var sortedArray = [];

        for(var i=0; i<partToArray.length; i++)
        {
            partToArray[i].displayOrder = orderArray[i];
        }

        $scope.contentData = partToArray;
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant