Как создать перетаскиваемые наборы полей в ExtJS 3.x

Я хотел бы создать ExtJS FormPanel, который позволяет пользователю изменять порядок списка наборов полей с помощью перетаскивания.

Я вижу, что очень легко сделать наборы полей перемещаемыми с помощью draggable: true, но как мне настроить dropzone? Я пытался следовать ряду примеров, но мне не повезло.

MyApp.FormPanel = Ext.extend(Ext.FormPanel,{
    title: 'Fields',

    fieldSetCount: 0,

    constructor: function(config){
        Ext.apply(this, config);

        this.tbar = [{
            text: 'Add Field Set',
            handler: this.addFieldSet,
            scope: this
        }];

        MyApp.FormPanel.superclass.constructor.call(this, config);
    },

    addFieldSet: function(){
        this.add({
            xtype: 'fieldset',
            title: 'Fieldset ' + this.fieldSetCount++,
            draggable: true
        });
        this.doLayout();
    },
});

person Hugh    schedule 11.10.2011    source источник


Ответы (1)


Вам нужно внедрить Ext.dd.DropZone, чтобы заархивировать это! См. Ext.JS 3.x API для более подробной информации об этом

Следующий пример не тестировался, но он должен показать вам трюк!

FormDropZone = function (form, config) {
    this.form = form;
    FormDropZone.superclass.constructor.call(this, form.view.scroller.dom, config);
};


Ext.extend(FormDropZone, Ext.dd.DropZone, {
    onContainerOver: function (dd, e, data) {
        return dd.form !== this.form ? this.dropAllowed : this.dropNotAllowed;
    },
    onContainerDrop: function (dd, e, data) {
        if (dd.form !== this.form) {
            this.form.onFormDrop(this.form, data.selections, dd.form);
            return true;
        }
        else {
            return false;
        }
    },
    containerScroll: true
});


DDform = Ext.extend(Ext.form.formPanel, {
    // configuration
    initComponent: function () {
        var config = {};
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        DDform.superclass.initComponent.apply(this, arguments);
    },
    onRender: function () {
        DDform.superclass.onRender.apply(this, arguments);
        this.dz = new FormDropZone(this, { ddGroup: this.ddGroup || 'formDD' });
    },  
    onFormDrop: Ext.emptyFn
});

Надеюсь, это поможет вам!

person sra    schedule 25.10.2011