2013-10-17 40 views
0

在Ext.grid.EditorGridPanel表如何拆分單元格,有兩個或三排?Ext JS的EditorGridPanel - 如何拆分單元格中顯示多行

像下面的圖片

enter image description here

+0

哪個Ext JS的版本? – Krzysztof

+0

ExtJS的3.4版本 – shiva

+0

在內線4+很容易 - 你可以,而不是分裂,只設置rowspan的第一列細胞。另一方面,在Ext 3.4中並不那麼容易。每行都被渲染爲用div包裹的獨立表格,所以rowspan將不起作用。最簡單的方法可能是改變第一列中的單元格樣式並將它們渲染到下面的單元格中。我稍後會想出一些事情。 – Krzysztof

回答

2

我成功地做到了一種行跨度,而不是行分裂的。海事組織更容易,它看起來像附加圖像上的網格一樣。示例代碼:

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'); 
     } 
    } 
}); 

此代碼通過應用position: absolute和足夠大的尺寸,以低於覆蓋行改變了.x-grid3-cell-inner風格。請注意,您還必須應用一些不透明背景才能使其工作。工作樣本:http://jsfiddle.net/RpxZ5/8/

我第一次寫代碼的Ext JS 4,如果你有興趣,這裏是工作示例:http://jsfiddle.net/wQSQM/3/

+0

這是完美的! – shiva

+0

它確實有效,但有一個問題。由於'.X-GRID3 - 細胞inner'施加'位置:absolute'的'forcefit'功能停止工作對於該行。你可以檢查你提供的jsfiddle。任何想法如何解決? 這個問題只在3.4版本中。它可以與4.x一起使用 –

相關問題