如何在extjs中显示与树面板的商店记录不同的单元格值?

时间:2016-04-26 13:08:23

标签: spring extjs

我在项目中使用extjs 6.0.1作为前端,使用spring作为后端代码。我有一个UI或页面使用树面板来显示数据。 以下是商店和型号代码。

Ext.define('SomeTreeStore', {
extend: 'Ext.data.TreeStore',
model: 'SomeTreeModel',
autoSync: false,
autoLoad: false,
root: {
    id: 0,
    expanded: false,
    description: 'SomeData'
},
proxy: {
    type: 'ajax',
    writer: {
        writeAllFields: true,
        allowSingle: false,
        rootProperty: 'children',
        clientIdProperty: 'clientId'
    },
    reader: {
        type: 'json',
        rootProperty: 'children',
        successProperty: 'success'
    },
    api: {
        create: 'rest/test/adddata',
        read: 'rest/test/getdata',
        update: 'rest/test/updatedata',
        destroy: 'rest/test/deletedata'
    },
    headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json;charset=utf-8'
    }
}
});


Ext.define('SomeTreeModel', {
extend: 'Ext.data.TreeModel',
idProperty: 'id',
identifier: 'negative',
fields: [
    { name: 'id', type: 'int' },

    { name: 'item', type: 'string' },
    { name: 'data1', type: 'string' },
    { name: 'data2', type: 'number' },
    { name: 'unit', type: 'string' },
    { name: 'Rate', type: 'number' },
    { name: 'Amount', type: 'number' }
]
});

我必须以单位为基础显示费率和金额。 例如。如果单位== PM,那么我只需要在树面板中显示费率和金额值,否则我必须显示空白值或什么都没有。

同样我使用下面的代码。

{
    text: 'Amount',
    flex: 1.5,
    sortable: false,
    dataIndex: 'Amount',
    align: 'right',
    renderer: function (value, metaData, record, rowIdx, colIdx, store, view) {

        if(record.get('unit') == 'PM'){
            return Ext.util.Format.number(value, '0.00');
        }else{
            return '';
        }
    }

}      

但是这段代码也会更新商店价值。每当我更新某些内容时,它都会使用空白值来更新数据库。

我还必须允许在单位价值的基础上更新费率和金额。

请告诉我显示与商店值不同的treepanel值的方法。

1 个答案:

答案 0 :(得分:1)

这段代码怎么样?
为了避免单元格值和商店之间的绑定,不使用dataIndex属性。

{
    text: 'Amount',
    flex: 1.5,
    sortable: false,
    //dataIndex: 'Amount',
    align: 'right',
    renderer: function (value, metaData, record, rowIdx, colIdx, store, view) {

        if(record.get('unit') == 'PM'){
            //return Ext.util.Format.number(value, '0.00');
            return Ext.util.Format.number(record.get('Amount'), '0.00');
        }else{
            return '';
        }
    }
}

<强>更新
我忘了考虑

  

而且我还必须允许在此基础上更新费率和金额   单位价值。

您必须手动更新商店值,如下所示。

{
    text: 'Amount',
    flex: 1.5,
    sortable: false,
    //dataIndex: 'Amount',
    align: 'right',
    renderer: function (value, metaData, record, rowIdx, colIdx, store, view) {

        if(record.get('unit') == 'PM'){
            var FormattedAmount = Ext.util.Format.number(record.get('Amount'), '0.00');
            record.set('Amount', FormattedAmount);  // Update the store manually.

            return FormattedAmount;
        }else{
            return '';
        }
    }
}