使用PivotGrid的ExtJS单元格选择模型不起作用

时间:2010-10-07 19:08:08

标签: javascript extjs

我正在尝试更改PivotGrid的SelectionModel,但它无法正常工作。这是我的代码。有人能说出我做错了什么。

我需要使用cellSelectionModel,因为我想向下钻取,我需要顶部和左侧轴来获得交叉点。

我也尝试过EXTJS 3.3 API中的'cellclick'事件而没有运气。任何人都可以获得除默认RowSelectionModel以外的选择模型吗?

var pivotAccumGrid = new Ext.grid.PivotGrid({
    store     : my_store,
    aggregator: 'count',
    measure   : 'my_field',
    sm: new Ext.grid.CellSelectionModel({  //I have also tried selModel for key
        listeners: {
            cellselect: function(sm,row,col) {
                Ext.Msg.alert('click','got a click!');
            }
        }
    }),
    topAxis: [ {dataIndex: 'top_field'},{dataIndex: 'top_field2'}  ],
    leftAxis: [ {dataIndex: 'left_field',  width: 80} ],
});

1 个答案:

答案 0 :(得分:1)

这是一个快速修复,它在meta中向PivotGridView引入了一个新属性,因此稍后可以用它来取消单元格索引。大部分代码没有任何不同,只是在meta.id中引入renderRows以及在meta.id中分割getCellIndex

Ext.override(Ext.grid.PivotGridView, {    
    renderRows : function(startRow, endRow) {
        var grid          = this.grid,
            rows          = grid.extractData(),
            rowCount      = rows.length,
            templates     = this.templates,
            renderer      = grid.renderer,
            hasRenderer   = typeof renderer == 'function',
            getCellCls    = this.getCellCls,
            hasGetCellCls = typeof getCellCls == 'function',
            cellTemplate  = templates.cell,
            rowTemplate   = templates.row,
            rowBuffer     = [],
            meta          = {},
            tstyle        = 'width:' + this.getGridInnerWidth() + 'px;',
            colBuffer, column, i;

        startRow = startRow || 0;
        endRow   = Ext.isDefined(endRow) ? endRow : rowCount - 1;

        for (i = 0; i < rowCount; i++) {
            row = rows[i];
            colCount  = row.length;
            colBuffer = [];

            rowIndex = startRow + i;

            //build up each column's HTML
            for (j = 0; j < colCount; j++) {
                cell = row[j];

                meta.id    = i + '-' + j;
                meta.css   = j === 0 ? 'x-grid3-cell-first ' : (j == (colCount - 1) ? 'x-grid3-cell-last ' : '');
                meta.attr  = meta.cellAttr = '';
                meta.value = cell;

                if (Ext.isEmpty(meta.value)) {
                    meta.value = '&#160;';
                }

                if (hasRenderer) {
                    meta.value = renderer(meta.value);
                }

                if (hasGetCellCls) {
                    meta.css += getCellCls(meta.value) + ' ';
                }

                colBuffer[colBuffer.length] = cellTemplate.apply(meta);
            }

            rowBuffer[rowBuffer.length] = rowTemplate.apply({
                tstyle: tstyle,
                cols  : colCount,
                cells : colBuffer.join(""),
                alt   : ''
            });
        }

        return rowBuffer.join("");
    },

    getCellIndex : function(el) {
        if (el) {
            var match = el.className.match(this.colRe),
                data;

            if (match && (data = match[1])) {
                return parseInt(data.split('-')[1], 10);
            }
        }
        return false;
    }
});