javascript - Extjs网格面板一列背景颜色更改另一列值

标签 javascript extjs extjs3

我有一个 Extjs 编辑器网格面板,在其中我必须根据另一列值的值更改一列的 css 那么如何做到这一点我无法使用渲染器功能,因为它在 onload 上工作还有其他方法吗?我正在附加代码,其中我有性别列和 id 列,因此当性别列选择男性时,ID 的背景颜色应更改为粉红色,否则不知道该怎么做。

  {
            id: 'value',
            name: 'value',
            header: 'Gender',
            dataIndex: 'insured',
            width: 100,
            editor: new fm.ComboBox({

                typeAhead: true,
                displayField: 'gender',
                mode: 'local',
                transform: 'gender',
                triggerAction: 'all',
                selectOnFocus: true,
                forceSelection: true,
                stripeRows: true,
                lazyRender: true,
                listeners: {

                    }
                }
            })
        },
  {
        id: 'ID',
        name: 'ID',
        header: 'ID',
        dataIndex: 'ID',
        width: 100,
        hidden: true,
        editor: new fm.TextField({
            allowBlank: true,
            maxLength: 500
        })
    }

最佳答案

这适用于简单渲染

CSS:

.custom-column
{
    background-color: #ccc; 
}

JavaScript:

columns: [{
    dataIndex: 'name',
    renderer: function (value, meta) {
        meta.css = 'custom-column';
        return value;
    }
}]

编辑:

您可以使用getRowClass在渲染期间将自定义 CSS 类应用到行。

Override this function to apply custom CSS classes to rows during rendering. This function should return the CSS class name (or empty string '' for none) that will be added to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string (e.g. 'my-class another-class').

Javascript:

columns: [{
    dataIndex: 'ID',
    ...
    tdCls: 'ID' //add table css class
}],

viewConfig: {
    getRowClass: function(record, index) {
        var gender = record.get('insured');

        if (gender === 0) {
        //male
            return 'gender-male';
        } else if (gender === 1) {
        //female
            return 'gender-female';
        } else {
        //unknown
            return 'gender-unknown';
        }
    }
}

附加CSS:

.gender-male .ID {
    background-color: #088da5;
}
.gender-female .ID {
    background-color: #f799af;
}
.gender-unknown .ID {
    background-color: #BADA55;
}

关于javascript - Extjs网格面板一列背景颜色更改另一列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15110710/

相关文章:

mysql - ExtJS Store - 将特定字段复制到存储

javascript - react : how to filter an array of objects in props

javascript - 如何使用 Protractor 从带有 ng-reflect-value 的选择中获取文本?

javascript - 复选框选择模型 : How to check rows by default?

javascript - ExtJs Tree加载顺序

javascript - extjs 3.4 如何动态添加复选框到工具栏

javascript - EXTJS 网格行着色失败

javascript - 当我的页面有 4 个以上的网格时,如何在页面中设置 4 个网格的样式?

javascript - 修改我的代码 : currently using toggle() and toggleClass()

javascript - Siesta:组件查询断言不起作用