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/

相关文章:

javascript - 如何在 ExtJS 中为 AJAX 调用创建 JSON?

ajax - 如何在ExtJs AjaxRequest中实现CSRFGuard?

javascript - ExtJS 3.4 : How to add a custom renderer dynamically to a PropertyGrid?

c# - 如何限制用户在文本框中输入英文字符

javascript - 使用 ExtJS 捕获功能键事件 (F1-F12)

javascript - 如何用ExtJs ajax responseText替换元素

javascript - 在 extjs 4 中更改组合框的动态表单字段

javascript - 将用户数据存储在本地存储的对象中

javascript - 在 JavaScript 中动态构建表单字段名称并分配值

javascript - 在 Internet Explorer 中无法将 DIV 导出为 PDF