2

所以我有一个两列的网格,第一列只有文本,第二列需要有一个自定义控件(带有一个复选框和一个组合框)

检查屏幕:

这是一个screenie的链接: 屏风

问题:_

当我单击更新以更新行时。第一得到更新,但第二列没有

我天真地getValue()在我的自定义控件中添加了一个,但没有运气!(注意:我使用的是行编辑插件)

这是我的代码:

Ext.define('MainGrid', {
    extend: 'Ext.grid.Panel',
    //defs for all the toolbars and buttons
    plugins: [rowEditing],
    columns: [
                {
                    xtype: 'rownumberer'
                },
                {
                    xtype: 'gridcolumn',
                    text: 'Column Titles',
                    dataIndex: 'ColumnTitle',
                    editor: {
                        xtype: 'textfield',
                    }
                },
                {
                    xtype: 'gridcolumn',
                    sortable: false,
                    align: 'center',
                    dataIndex: 'IssueCondition',
                    editor: {
                        xtype: 'reportpopulation'
                    }]
});

这里reportpopulation自定义控件。这是它的代码:

Ext.define('SelectPopulation', {
    extend: 'Ext.container.Container',
    itemId: 'ctrSelectpopulation',
    alias: 'widget.reportpopulation',
    layout: {
        type: 'hbox'
    },
    initComponent: function () {
      //code to add combo box and checkbox snipped
      ....
    },
    getValue: function () {
        //This doesn't work! 
        return "Booo";
    }
});

所以点击更新不会:

  • 有什么我想念的吗?
  • 我应该从 FieldBase 继承吗?我可以使用多个控件并使用 FieldBase 创建类似于 screenie 的东西吗?
4

1 回答 1

1

这有效,即使您getValue()正在工作,问题是您在该网格列 ( IssueCondition) 上使用了自定义类型值并且没有为其指定任何渲染器,请尝试以下操作:

Ext.define('MainGrid', {
extend: 'Ext.grid.Panel',
height: 300,
plugins: [Ext.create('Ext.grid.plugin.RowEditing', {
    clicksToEdit: 1
})],
columns: [{
    xtype: 'rownumberer'
}, {
    xtype: 'gridcolumn',
    text: 'Column Titles',
    dataIndex: 'ColumnTitle',
    editor: {
        xtype: 'textfield'
    }
}, {
    xtype: 'gridcolumn',
    sortable: false,
    text: "Issue Condition",
    align: 'center',
    dataIndex: 'IssueCondition',
    width: 200,
    editor: {
        xtype: 'reportpopulation'
    },
    renderer: function (v, attr, rec) {
        console.info(arguments);
        return 'cb: ' + rec.data.IssueCondition.cb + ' combo: ' + rec.data.IssueCondition.combo;
    }
}],
store: Ext.create("Ext.data.Store", {
    fields: ["ColumnTitle", "IssueCondition"],
    proxy: {
        type: "memory",
        reader: {
            type: "json"
        }
    }
})
});

Ext.define('SelectPopulation', {
extend: 'Ext.container.Container',
itemId: 'ctrSelectpopulation',
alias: 'widget.reportpopulation',
layout: {
    type: 'hbox'
},
initComponent: function () {
    Ext.apply(this, {
        items: [{
            xtype: "checkbox"
        }, {
            xtype: "combobox",
            allowBlank: false,
            store: [
                [0, 'Zero'],
                [1, 'One'],
                [2, 'Two']
            ]
        }]
    });
    this.callParent(arguments);
},
getValue: function () {
    return {
        cb: this.child('checkbox').getValue(),
        combo: this.child('combobox').getValue()
    };
}
});

请注意,这只是一个示例。

在这里检查小提琴

希望这可以帮助。

于 2013-01-07T12:36:30.600 回答