如何在Extjs中动态设置xtype gridcolumn的dataIndex值

How to dynamically set the value of dataIndex for xtype gridcolumn in Extjs

本文关键字:gridcolumn xtype dataIndex 设置 动态 Extjs      更新时间:2023-09-26

我想根据数据的可用性动态设置网格列的dataIndex值。我的代码如下:

型号:

    {
        name: 'idCcyAcc',
        mapping: 'order.idCcyCreditAcc'
    },
    {
        name: 'idCcyFullAcc',
        mapping: 'order.idCcyCreditFullAcc'
    },

视图:

    {
                xtype: 'gridcolumn',
                filter: {
                    xtype: 'textfield'
                },
                filterable: true,
                dataIndex: 'idCcyCreditAcc', 
                text: 'Credit Account Currency',
                id: 'paymentPanelGridCrAccCcy',
                width: 150,
                renderer: Ext.bind(this.onRenderCell, this)
    },

我如何根据dataType(即)动态设置dataIndex的值

    if(type=Internal){
    dataIndex: 'idCcyCreditAcc'
    } else {
    dataIndex: 'idCcyCreditFullAcc'
    }

感谢您的帮助。

我在模型中做了以下操作,达到了目的:

    {
        name: 'idCcyAcc',
        convert: function(value, record){
            if(record.data.idProductType == 'Internal') {
                return record.data.idCcyCreditFullAcc;
            } else {
                return value;
            }
        },
        mapping: 'order.idCcyCreditAcc'
    },