In JqueryUI sortable, When the user drags a item, change event called. I got this on below example.
jsFiddle code here
stop: function(event, ui) {
console.log("New position: " + ui.item.index());
},
change: function(event, ui) {
// When the item postion is changed while dragging a item, I want it's position
console.log("New position: " + ui.item.index());
}
In my code When the user drags a item (Item7) and changes the position , while dragging a item and changing the position . I want to get the position of a dragging item.
I just saw a answer here : jQuery UI Sortable Position
In the above link, position value (ui.item.index()) is accessed on Stop function, while dragging a item, I want it's position (on change function) ? Any Idea ?
I need this because when the user tries to place a item7 after a item2, I will do some validation getting values from previous Item2 (If I know the current position of the dragging item, Then only I can access previous item) . If the validation is success, It can be placed or I have to show some message.
The jQuery UI Sortable update event is used to trigger when the user stopped sorting and the DOM position has changed. Initialize the sortable widget with the update callback function. Bind an event listener to the sortable update event. event: This event is triggered when the user stopped the sorting with a position change of DOM.
JqueryUI - Sortable. jQueryUI provides sortable() method to reorder elements in list or grid using the mouse. This method performs sortability action based upon an operation string passed as the first parameter.
Description: Reorder elements in a list or grid using the mouse. The jQuery UI Sortable plugin makes selected elements sortable by dragging with the mouse. Note: In order to sort table rows, the tbody must be made sortable, not the table. The sortable widget uses the jQuery UI CSS framework to style its look and feel.
The sortable that the item comes from if moving from one sortable to another. The jQuery object representing the element being used as a placeholder. This event is triggered when a sortable item is moved away from a sortable list. Note: This event is also triggered when a sortable item is dropped.
If you want to get the index of what's currently hovered, try using placeholder
.
change: function(event, ui) {
console.log("New position: " + ui.placeholder.index());
}
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With