Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EmberJS + jqueryUI + sortable

I wanted to create a list (or table) with some sortable items in emberjs and jqueryui.

I uploaded a sample on JSFiddle: http://jsfiddle.net/KCxxu/

When I start it and click remove it works perfect. But when I first reorder the items and click remove again nothing happens till I click both delete buttons.

Any ideas?

Thanks a lot!

like image 653
najjannaj Avatar asked May 16 '26 07:05

najjannaj


1 Answers

in your del function add contentWillChange() and contentDidChange()

Seems to work now

window.App = Ember.Application.create({});

Item = Ember.Object.extend({
    id : null,
    name : null
});

App.listController = Ember.ArrayProxy.create({
    content : [
        Item.create({id: 1, name : 'test'}),
        Item.create({id: 1, name : 'test2'}),
    ],
});

App.ListView = Ember.View.extend({
    tagName : 'tr',

    didInsertElement : function() {
        var me = this;
        this._super();

        // Make list sortable
        this.$().parent("tbody").sortable({
            items : 'tr',
            opacity : 0.6,
            axis : 'y'
        });
    },

    del : function(event) {
        var item = event.context;
        App.listController.contentWillChange();
        App.listController.removeObject(item);
        App.listController.contentDidChange();
    }
});

http://jsfiddle.net/KCxxu/3/

like image 58
alexl Avatar answered May 17 '26 20:05

alexl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!