Skip to content

Doesn't work for dynamic elements #30

@pushpinderbagga

Description

@pushpinderbagga

Hey Johnny,

Thanks for the rocking plugin. I was trying to order dynamically added elements and it doesn't work. Gives an error - $item is undefined.

Any clue on how can I accomplish this?

Below is my code

        $("ul.order_list").sortable({
            handle: '.grab',
            onDragStart: function ($item, container, _super) {
                var offset = $item.offset(),
                pointer = container.rootGroup.pointer
                adjustment = {
                    left: pointer.left - offset.left,
                    top: pointer.top - offset.top
                }
                _super($item, container)
            },
            onDrag: function ($item, position) {
                $item.css({
                    left: position.left - adjustment.left,
                    top: position.top - adjustment.top
                })
            }, 
            onDrop: function ($item, container, _super) {
                $item.removeClass("dragged").removeAttr("style");
                $("body").removeClass("dragging");
                newOrder = $("ul.order_list").sortable("serialize").get();
                postPhotoListOrder(newOrder);                    
            }
        });

Thanks a lot mate!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions