extJs 4网格自定义-末尾的总行

extJs 4 grid customization - Total row at the end

本文关键字:网格 自定义 extJs      更新时间:2023-09-26

我想要一个只有两列的网格,一列用于名称,另一列用于百分比。最后一行的名称为"Total",总百分比为"percentage"。仅此行的样式与其他行不同。请指导我如何做到这一点。谢谢

有一个网格功能可以实现这一点。文档中的此处介绍了它,并提供了一些如何使用它的示例。

您还可以通过在css中提供自己的x-grid-row-summary类实现来自定义样式。

编辑

这里有一些设置摘要行样式的例子,正如你所看到的,有几种方法可以实现它。要意识到,在viewready事件发生之前,摘要行不能被引用,它在afterrender事件时还没有准备好,所以我把所有这些逻辑都放在viewready监听器中:

Ext.create('Ext.grid.Panel', {
    features: [{
        ftype: 'summary'
    }],
    // other grid configs ...
    listeners: {
        viewready: function(grid) {
            // get reference to the summary row
            var summaryRow = grid.view.el.down('tr.x-grid-row-summary');
            // this will apply a css class to the row, in this example,
            // I am applying the extjs grid header style to my summary row
            summaryRow.addCls('x-grid-header-ct');
            // or, to do it all in javascript as you mentioned in the comment
            // first you would create a style object, I took these style
            // properties from the .x-grid-header-ct
            aStyleObject = {
                cursor: 'default',
                zoom: 1,
                padding: 0,
                border: '1px solid #d0d0d0',
                'border-bottom-color': '#c5c5c5',
                'background-image': 'none',
                'background-color': '#c5c5c5'
            }
            // then you pass the style object using setStyle
            summaryRow.setStyle(aStyleObject);
            // or you could set the style for each cell individually using 
            // addCls or setStyle:
            Ext.Array.each(summaryRow.query('td'), function(td) {
                var cell = Ext.get(td);
                cell.addCls('some-class');
                // or
                cell.setStyle(anotherStyleObject);
            });
        }
    }
});

如果我们有摘要行(像这样),我们可以在特定页面上使用CSS。

<style>
.x-grid-row-summary .x-grid-cell{
    background-color: #f00 !important;
    font-size: x-large !important;
}