Serhii Zharkov
Serhii Zharkov

Reputation: 564

How to access existing instance of Sortable.js element and pass new options?

I use https://github.com/RubaXa/Sortable for my project with sorting and dragging cards. I need to change options of some Sortable groups dynamically and just don't understand how I can access existing sortable instances and pass new options. Does anybody have a solution for that?

Let's say I created new instance of Sortable:

Sortable.create(requests, {
  group: {
    name: 'requests',
    put: (['standBy', 'rooms']).concat(roomCards)
  },
  animation: 250
});

How then I can access this instance and pass new options? Didn't find anything in documentation.

Upvotes: 1

Views: 1237

Answers (1)

Andrew Anderson
Andrew Anderson

Reputation: 441

Hah! I'm working through this right now too. The only method I'm seeing so far is this:

Sortable.active

This does not seem to work in a Browserify context, however. Tracing back through the code it seems that a reference to the Sortable instance is stored here:

https://github.com/RubaXa/Sortable/blob/97633e4e8a96c267bc574a68ea0cd18165296727/Sortable.js#L232

But the expando variable is defined as 'Sortable' + (new Date).getTime(). Seems that there isn't an easy way in the default setup to do what is needed.

At this point the only solution I'm seeing is to do one of the following:

  1. Maintain an array of pointers to the instances.
  2. Use the jQuery wrapper, which is what I ended up doing.

Upvotes: 0

Related Questions