Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

Sortable on dynamically created elements

Open Evin89 opened this issue 7 years ago • 6 comments

Hi all,

Not directly an issue, but I'm trying to get sortable working on divs I dynamically create. Any idea how to solve this? So far it doesn't seem to work.

Evin89 avatar Mar 13 '18 14:03 Evin89

I am not the author of this fiddle, but it does what you are looking for http://jsfiddle.net/06y0w14b/

EDIT: That's actually a complicated example with nested sortables. If you are looking for something a lot more simple, try this http://jsfiddle.net/tn0nr3b5/19/

activestylus avatar Mar 19 '18 00:03 activestylus

is there any way to initialize Sortable instance on element which is not present in DOM yet but will add dynamically later

azinkey avatar Apr 24 '19 07:04 azinkey

@azinkey If it works on an element that is not in the DOM then yes, but if not there is no special way to make it work

owen-m1 avatar Apr 24 '19 23:04 owen-m1

Thank you @activestylus! I'm coming from 2020 and you saved my day.

aissa-bouguern avatar Dec 30 '20 13:12 aissa-bouguern

I am not the author of this fiddle, but it does what you are looking for http://jsfiddle.net/06y0w14b/

EDIT: That's actually a complicated example with nested sortables. If you are looking for something a lot more simple, try this http://jsfiddle.net/tn0nr3b5/19/

I think what OP is referring to is going complete commando on the DOM. No DOM at all. He doesn't want to add dynamic elements to an already existing list, but want to create a sortable list that does not exist at all. I'm wanting to do the same thing. Creating the list dynamically with document.createElement() for instance. Like OP me too I've tried many many different ways to do this and the sortable must exist in the DOM if we want this to work.

webb24h avatar Nov 11 '21 04:11 webb24h

How did you solve this 😅 @Evin89

khalednadam avatar Feb 16 '24 18:02 khalednadam