1

我正在尝试根据同一行中另一个单元格中的值格式化一个 ExtJS treegrid 单元格。下面是我目前如何对其进行编码的概述。但是,这目前不起作用,因此我将不胜感激任何建议。谢谢!

function fn(v, values){
    if (values.alarm == 1) {
        return '<span style="color: red;">' + v + '</span>';
    }
    return v;
}

//new treegrid

columns:[{
    header: 'H1',
    width: 60,
    dataIndex: 'duration1',
    align: 'center',
    tpl: new Ext.XTemplate(
        '{duration1:this.doFormat}',
        {doFormat: fn()}
    )
}, {
    header: 'A1',
    width: 60,
    dataIndex: 'alarm1',
    align: 'center'
}]
4

2 回答 2

1

以下是我开发的解决方案,以防其他人遇到同样的问题。

//Treegrid formatting function
function fn(v, values){
    i = i + 1;
    switch(i){
        case 1: x = values.alarm1; break;
        case 2: x = values.alarm2; break;
        default: alert("x not assigned value");
    }
    if (x == 1) {return '<span style="background-color: red; width: 100%">' + v + '</span>';}
    else if(i == currenthour)
        {return '<span style="background-color:' + currentcolor + '; width: 100%">' + v + '</span>';}
    else
        {return '<span style="background-color:' + basecolor + '; width: 100%">' + v + '</span>';}  
}

//create the treegrid
columns:[
        {header: 'Name',dataIndex: 'name',width: 210},
        {header: 'H1', width: 60, dataIndex: 'duration1', align: 'center',              
            tpl: new Ext.XTemplate('{duration1:this.doFormat}', {doFormat: fn})},
            {header: 'A1', width: 0,dataIndex: 'alarm1' , visibility: false},
        {header: 'H2', width: 60, dataIndex: 'duration2',align: 'center',
            tpl: new Ext.XTemplate('{duration2:this.doFormat}', {doFormat: fn})},
            {header: 'A2', width: 0,dataIndex: 'alarm2' , visibility: false},
]
于 2011-03-15T00:19:14.323 回答
0

ExtJS 树网格有点不寻常,因为它并没有得到真正的支持,预计在 ExtJS 4 之前不会完全支持,此外,XTemplate 文档有点缺乏。

使用以下模板格式可能会更好:

tpl: new Ext.XTemplate('{[this.doFormat(values.duration1)]}', {
    doFormat: fn
})
于 2011-03-10T14:10:15.913 回答