Sortable: Deselect after drop

Created on 28 Aug 2019  路  6Comments  路  Source: SortableJS/Sortable

Hello :-)

Is there a way to deselect the selected items after grabbing them and dropping them on their new position? At the moment, the user has to deselect everything after dragging.

Thanks

question

Most helpful comment

@reicheltmediadesign Sorry, the JSBin link wasn't saving properly. JSBin should work now.
If you are getting that error, could you try to reproduce it in a JSBin? Sortable.utils should always be defined.

All 6 comments

@reicheltmediadesign Something like this:

new Sortable(el, {
    onEnd: function(evt) {
        for (let i in evt.items) {
            Sortable.utils.deselect(evt.items[i]);
        }
    }
});

Let me know if this solves it for you.

@owen-m1 no, doesn't change anything.

I currently have this:

var Sortable = new Sortable(el, {

    multiDrag: true,
    selectedClass: 'selected',
    animation: 150,
    onDrop: function(evt) {
      for (let i in evt,items) {
        console.log(evt.items[i]);
        Sortable.utils.deselect(evt.items[i]);
      }
    }
  })

It doesn't even log anything in console window (I added this line for testing purposes)

@reicheltmediadesign My bad.. it is actually the onEnd event, not onDrop.
Here is a working JSBin: https://jsbin.com/merayer/4/edit?js,output

@owen-m1 after I changed from onDrop to onEnd now it says in console:

(index):150 Uncaught TypeError: Cannot read property 'deselect' of undefined
at Sortable.onEnd ((index):150)
at dispatchEvent (Sortable.js:909)
at _dispatchEvent (Sortable.js:954)
at Sortable._onDrop (Sortable.js:2202)
at Sortable.handleEvent (Sortable.js:2231)

@reicheltmediadesign Sorry, the JSBin link wasn't saving properly. JSBin should work now.
If you are getting that error, could you try to reproduce it in a JSBin? Sortable.utils should always be defined.

@owen-m1 Interesting, I 'copied' your example to my application and now it works like a charm. Thank you very! much, you saved me hours if trying to get this to work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tom-sherman picture tom-sherman  路  3Comments

chrishaigy picture chrishaigy  路  3Comments

dwburdick picture dwburdick  路  3Comments

garygreen picture garygreen  路  3Comments

FINDarkside picture FINDarkside  路  3Comments