Add oldindex property to sortupdate event data#27
Add oldindex property to sortupdate event data#27flying-sheep wants to merge 1 commit intofarhadi:masterfrom
Conversation
knowing the old index is a useful feature for using this in an MVVC application, since the underlying array can be spliced instead of having to be rewritten.
AngularJS example:
```javascript
function SortableCTRL($scope) {
$scope.sortableArray = ['One', 'Two', 'Three'];
$scope.sortupdate = function(e, data) {
var start = data.oldindex,
end = data.item.index();
$scope.sortableArray.splice(end, 0,
$scope.sortableArray.splice(start, 1)[0]);
$scope.$apply();
};
setTimeout(function() {
$('#sortable')
.sortable()
.on('sortupdate', $scope.sortupdate);
});
}```
|
👍 Not just for MVC, old index is generally useful. |
|
Why not add newindex while we're at it? |
|
sortupdate is afaik triggered after the list has been resorted, so the current index is the new index. else we wouldn’t need the oldindex (as it would be the – still – current index) |
|
Right. To make things easier for myself, something like this would be viable? dragging.parent().trigger('sortupdate', {
item: dragging,
oldindex: index,
newindex: dragging.index()
}); |
|
sure, just: i do that in my example code: $('#sortable').sortable().on('sortupdate', function(e, data) {
var start = data.oldindex,
end = data.item.index();
});why would |
|
Ah. I lept before I looked. Was looking for exactly that bit of code. Thanks. |
|
This project has been discontinued by its author and the new mantained version is here. Since the projects have diverged a while ago I can't migrate issues and pull requests. Please try the new version and if the issue or pull request still makes sense, please resubmit it. Sorry for the inconvenience. |
|
you seem to do this, anyway: https://github.com/voidberg/html5sortable/blob/master/src/html.sortable.js#L94 |
knowing the old index is a useful feature for using this in an MVVC application, since the underlying array can be spliced instead of having to be rewritten.
AngularJS example: