Ext JS EditorGridPanel - 如何拆分单元格以显示多行

时间:2013-10-17 07:25:35

标签: extjs extjs3

在Ext.grid.EditorGridPanel表中如何拆分单元格有两三行?

如下图所示

enter image description here

1 个答案:

答案 0 :(得分:2)

我设法做了一种rowpan而不是行拆分。 IMO它更容易,它看起来与附加图像上的网格相同。示例代码:

var grid = new Ext.grid.EditorGridPanel({
    [...],

    // hook up events
    initComponent: function () {
        Ext.grid.GridPanel.prototype.initComponent.call(this);

        this.getView().on('refresh', this.updateRowSpan, this);
        this.getView().on('rowupdated', this.updateRowSpan, this);
    },

    onLayout : function(vw, vh) {
        this.updateRowSpan();
    },

    // set span on rows
    updateRowSpan: function() {
        var columns = this.getColumnModel().config,
            view = this.getView(),
            store = this.getStore(),
            rowCount = store.getCount(),

            column = columns[0], // put propert column index here
            dataIndex = column.dataIndex,

            spanCell = null,
            spanCount = null;
            spanValue = null;

        for (var row = 0; row < rowCount; ++row) {
            var cell = view.getCell(row, 0),
                record = store.getAt(row),
                value = record.get(dataIndex);

            if (spanValue != value) {
                if (spanCell !== null) {
                    this.setSpan(Ext.get(spanCell), spanCount);
                }

                spanCell = cell;
                spanCount = 1;
                spanValue = value;
            } else {
                spanCount++;
            }
        }

        if (spanCell !== null) {
            this.setSpan(Ext.get(spanCell), spanCount);
        }
    },

    // set actual span on row
    setSpan: function(cell, count) {
        var view = this.getView(),
            innerCell = Ext.get(cell.down('*')),
            height = cell.getHeight(),
            width = cell.getWidth();

        cell.setStyle('position', 'relative');
        if (count == 1) {
            innerCell.setStyle('position', '');
            innerCell.setStyle('height', '');
            innerCell.setStyle('height', '');
        } else {
            innerCell.setStyle('position', 'absolute');
            innerCell.setStyle('height', (height * count - cell.getPadding('tb') - innerCell.getPadding('tb')) + 'px');
            innerCell.setStyle('width', (width - cell.getPadding('lr') - innerCell.getPadding('lr')) + 'px');
        }
    }
});

此代码通过应用.x-grid3-cell-inner来更改position: absolute的样式,并且足够大以覆盖下面的行。请注意,您还必须应用一些不透明的背景才能使其正常工作。工作样本:http://jsfiddle.net/RpxZ5/8/

我首先为Ext JS 4编写代码,如果您有兴趣,这里有工作示例:http://jsfiddle.net/wQSQM/3/