Created
September 19, 2012 17:00
-
-
Save kjantzer/3750782 to your computer and use it in GitHub Desktop.
jQuery sortableWithIndexWatch - modified jquery ui sortable widget to store before and after index of moved item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// custom Sortable widget - gets before and after index of moved item | |
// https://gist.github.com/3750782 | |
$.widget("ui.sortableWithIndexWatch", $.extend({}, $.ui.sortable.prototype, { | |
_trigger: function() { | |
switch(arguments[0]){ | |
case 'start': | |
this.currentItem.indexStart = this.currentItem.index(); | |
break; | |
case 'update': | |
this.currentItem.indexEnd = this.currentItem.index(); | |
break; | |
} | |
return $.ui.sortable.prototype._trigger.apply(this, arguments); | |
} | |
})); |
How do I get to the currentItem attribute?
I have tried:
$(this).data().ui-sortable and $ (this).data().uiSortable but both give undefined
Just for a reference: use $(this).data()['ui-sortable'].currentItem in this case.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a question about this... I am in my sortable receiver function like this:
Here I have $(this).data() which is giving me:
in this object I have ui-sortable, which has the currentItem attribute which is what I need...
How do I get to the currentItem attribute?
I have tried:$(this).data().ui-sortable and $ (this).data().uiSortable but both give undefined... Thank you so much for you help!