ExtJS 4网格分组标题颜色

问题描述 投票:0回答:1

我有一个分组网格,以下是组标题定义:

xtype:  'gridpanel',
itemId: 'PRG_GRID',
layout: 'fit',
region: 'center',
store:  'PRGStore',
features: [
    Ext.create('Ext.grid.feature.GroupingSummary', {
       ftype: 'groupingsummary',
       id: 'groupSummary',
       groupHeaderTpl: '<br>&nbsp&nbsp<font size="2" color="#4169E1"><b>' +
        ' {[values.name == 1 ? "Above 80%" : ' +
         '[values.name == 2 ? "Above 50%" : ' +
           '[values.name == 3 ? "Above 50%" : ' +
            '[values.name == 4 ? "Notching" : ' +
             '[values.name == 77 ? "Contracted" : ' +
              '"TRASH"] ] ] ] ]} </b><br><br>',
       startCollapsed: true
  })
],
columns: {
...

一切都运作良好,但我想显示不同颜色的最后一个标题“TRASH”,然后#4169E1,例如红色的。我找不到合适的方法来做到这一点。真好帮忙吗?

extjs4
1个回答
1
投票

使用模板中的函数来简化它并避免重复。

groupHeaderTpl: [
  '{[this.styledHeader(values,parent)]}', {
    styledHeader: function(values, parent) {
      switch (values.name) {
        case 1:
          return this.wrapAnother("Above 80%");
        case 2:
          return this.wrapAnother("Above 50%");
        case 3:
          return this.wrapAnother("Above 50%");
        case 4:
          return this.wrapAnother("Notching");
        case 77:
          return this.wrapAnother("Contracted");
        default:
          return this.wrapTrash("TRASH");
      }
    },
    wrapTrash: function(value) {
      return this.wrapToFont('red', value);
    },
    wrapAnother: function(value) {
      return this.wrapToFont('#4169E1', value);
    },
    wrapToFont: function(color, value) {
      debugger
      return '<font size="2" color="' + color + '">' + value + '</font>'
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.