带组合框的属性网格

时间:2018-11-15 07:08:24

标签: javascript extjs combobox grid propertygrid

我有一些商店,它是数据。在面板上,它看起来如何“ fieldName”和文本字段(与调用的形式有所不同)。

例如,在一种形式上显示“名称文件”和字段,在另一种形式上显示:销售日期和日期字段。数据是动态形成的。

这是商店:

tableTempStore = new Ext.data.JsonStore({
    url: objectUrlAddress,
    baseParams: {
        'objectID': objectID
    },
    root: 'Fields',
    fields: [{
        name: 'Hint'
    }, {
        name: 'Type',
        type: 'int'
    }, {
        name: 'Value'
    }, {
        name: 'Index',
        type: 'int'
    }, {
        name: 'IsRequired',
        type: 'bool'
    }, {
        name: 'Identifier'
    }, {
        name: 'EnumList'
    }, {
        name: 'Directory'
    }, {
        name: 'Data'
    }],
    listeners: {
        load: function (obj, records) {
            Ext.each(records, function (rec) {
                var item = null;
                switch (rec.get('Type')) {
                case 0: // целое
                    item = new Ext.form.NumberField();
                    item.id = rec.get('Identifier');
                    item.fieldLabel = rec.get('Hint');
                    var isRequired = rec.get('IsRequired');
                    item.anchor = '100%';
                    item.allowBlank = !isRequired;
                    item.disabled = editDisabled;
                    item.value = rec.get('Data');
                    break;
                case 1: // вещественное
                    item = new Ext.form.NumberField();
                    item.id = rec.get('Identifier');
                    item.fieldLabel = rec.get('Hint');
                    var isRequired = rec.get('IsRequired');
                    item.anchor = '100%';
                    item.allowBlank = !isRequired;
                    item.allowDecimals = true;
                    item.disabled = editDisabled;
                    item.value = rec.get('Data');
                    break;
                case 5: // SQL-справочник
                    var dataValues = Ext.util.JSON.decode(rec.get('EnumList'));
                    var dataArray = Object.keys(dataValues).map(function (k) {
                        return [k, dataValues[k]]
                    });
                    item = new Ext.form.ComboBox({
                        typeAhead: true,
                        width: '100%',
                        triggerAction: 'all',
                        forceSelection: true,
                        editable: false,
                        hiddenName: rec.get('Identifier'),
                        mode: 'local',
                        store: new Ext.data.ArrayStore({
                            fields: [{
                                name: 'myId',
                                type: 'string'
                            }, {
                                name: 'displayText'
                            }],
                            data: dataArray
                        }),
                        valueField: 'myId',
                        displayField: 'displayText',
                        disabled: editDisabled
                    });
                    item.id = '_' + rec.get('Identifier');
                    item.anchor = '100%';
                    item.fieldLabel = rec.get('Hint');
                    var isRequired = rec.get('IsRequired');
                    item.allowBlank = !isRequired;
                    item.value = rec.get('Data');
                    break;
                }
                if (item != null) {
                    templateGrids.add(item);
                    columnsTable = item.__proto__.constructor.xtype;
                    var s = null;
                    else if (rec.get('Type') == 4) {
                        var dataValues = Ext.util.JSON.decode(rec.get('EnumList'));
                        var dataArray = Object.keys(dataValues).map(function (k) {
                            return [k, dataValues[k]]
                        });
                        combo = new Ext.grid.GridEditor(new Ext.form.ComboBox({
                            id: item.id,
                            allowBlank: item.allowBlank,
                            typeAhead: true,
                            lazyRender: true,
                            triggerAction: 'all',
                            forceSelection: true,
                            queryMode: 'local',
                            editable: false,
                            value: item.value,
                            hiddenName: rec.get('Identifier'),
                            mode: 'local',
                            store: new Ext.data.ArrayStore({
                                fields: [{
                                    name: 'myId',
                                    type: 'string'
                                }, {
                                    name: 'displayText',
                                    type: 'string'
                                }],
                                data: dataArray
                            }),
                            valueField: "myId",
                            displayField: "displayText",
                            disabled: editDisabled
                        }));
                    }
                    source[item.fieldLabel] = '';
                    grid.customEditors['Сохранить в'] = combo;

                    grid.getColumnModel().setConfig([{
                        header: "Поле"
                    }, {
                        header: "Значение",
                        dataIndex: '',
                        renderer: Ext.util.Format.comboRenderer(combo)
                    }]);
                    grid.setSource(source);
                };
            });
        }
    }
});

这是我的房地产表格:

grid = new Ext.grid.PropertyGrid({
    url: objectUrlAddress,
    id: 'propGrid',
    autoFill: true,
    autoHeight: true,
    width: 200,
    store: tableTempStore,
    width: 600,
    style: 'margin:0 auto;margin-top:10px;'
});

组合框问题。它在单元格上显示itemValue而不是fieldValue,但我不知道如何解决此问题。我能怎么做?预先感谢。

为了渲染,我使用了功能:

Ext.util.Format.comboRenderer = function (combo) {
    return function (value) {
        var record = combo.findRecord(combo.valueField, value);
        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
    }
};

但是没有用。

0 个答案:

没有答案