ExtJS Grid Panel - Multiple "rows" per row?

Chewpers picture Chewpers · May 23, 2011 · Viewed 9.6k times · Source

We have an ExtJS Grid Panel that has grown to include too many columns (imo), so I am looking into enfolding some data into "sub-rows" of the main row. Like:

Data1 | Data2 | Data3 | Data4 | Data5
  Some additional data that spans
Data1 | Data2 | Data3 | Data4 | Data5
  Some additional data that spans

I am aware of the expander plugin, but we wouldn't need the expand/collapse functionality and always need the sub-rows open.

Any thoughts or ideas?

Thanks in advance.

Answer

Dzhu picture Dzhu · Jun 6, 2011

If you're using ExtJS-4,

// ...
var rowBodyFeature = Ext.create('Ext.grid.feature.RowBody', {
    getAdditionalData: function(data, rowIndex, record, orig) {
        var headerCt = this.view.headerCt,
        colspan  = headerCt.getColumnCount();
        return {
            rowBody: "HELLO WORLD!", // do something with record
            rowBodyCls: this.rowBodyCls,
            rowBodyColspan: colspan
        };
    }
});

Ext.create('Ext.grid.Panel', {
    // ...
    features: [rowBodyFeature]
    // ...
});

If using ExtJS-3, try:

new Ext.grid.GridPanel({
    //...
    viewConfig: {
        enableRowBody: true,
        getRowClass: function(record, rowIndex, p, store) {
            p.body = 'HELLOW WORLD: ' + record.get('attribute');
            return 'x-grid3-row-expanded';
        }
    }