如何将类添加到由摘要功能生成的网格的一个单元格

How do I add a class to one cell of the grid generated by the Summary feature?

本文关键字:网格 单元格 一个 功能 添加      更新时间:2023-09-26

使用摘要功能创建网格后,我能够通过获取特征并访问与该功能关联的属性来访问列的摘要:

// inside the grid definition with two columns 
// that access dataIndex 'count1' and 'count2'
listeners: {
    viewready: function(grid) {
        var summaryRow = grid.getView().getFeature(0).summaryRecord.data;
        console.log(summaryRow.count1);
        console.log(summaryRow.count2);
    }
}

我想在表示summaryRow.count1的单元格中添加一个"tot-count1"类,在表示summaryRow.count2的单元格中添加一个"tot-count2"类。

似乎通常 ExtJS 开发人员只会大惊小怪地将类应用于网格的整行。如果我只想选择插件的行,我需要做的就是Ext.dom.Query.select('.x-grid-row-summary'......当我想要一个 Ext.dom.Element 以利用 Ext.dom.AbstractElement 的 addCls() 方法时,它会返回一个 HTMLElement。

我正在考虑类似以下内容:

// get the Ext.dom.Element representing the cell
var cell1 = ???
// call the addCls method
cell1.addCls('tot-count1');

我曾经使用在列配置中设置的summaryRenderer函数。

Ext.define(..., {
    columns: [{
        header: 'blah-blah',
        dataIndex: 'foo',
        summaryType: 'sum',
        summaryRenderer: function (value) {
            return Ext.String.format('<span class={0}>{1}</span>', 'tot-count1', value);
        }
    }],
    features: [{
        ftype: 'summary'
    }]
});