简体   繁体   English

如何使用ExtJS Grid 4.1使用行/列跨度制作类似表的结构

[英]How to make a table-like structure with row/colspans using ExtJS Grid 4.1

我需要使用具有colspan和rowspan功能的ExtJS 4.1网格实现逻辑。

Solution One: ExtJS Grid with rowSpan/colSpan 解决方案一:具有rowSpan / colSpan的ExtJS Grid

If you use a normal ExtJS grid, with one row per parameter value, you can (ab)use the renderer somehow: 如果您使用普通的ExtJS网格(每个参数值一行),则可以某种方式使用(ab)渲染器:

renderer:function(value, meta, record, rowIndex, colIndex, store, view) {
    var columnManager = view.ownerCt.getColumnManager(),
        previousRecord = store.getAt(rowIndex-1),
        nextRecord = store.getAt(rowIndex+1),
        column = columnManager.getHeaderAtIndex(colIndex),
        previousColumn = columnManager.getHeaderAtIndex(colIndex-1),
        nextColumn = columnManager.getHeaderAtIndex(colIndex+1),
        cellAbove = view.getCell(previousRecord,column),
        cellBelow = view.getCell(nextRecord,column),
        cellLeft = view.getCell(record, previousColumn),
        cellRight = view.getCell(record, nextColumn);
    ...
    if(someCondition) {
        meta.tdAttr='rowSpan=4';
    } else if (someOtherCondition /* any of the previous three records has someCondition */) {
        meta.tdStyle='display:none';
    }
    return value; // Don't forget this, or else your cell is empty!
}`

In a similar fashion, I have once implemented a renderer that merged adjacent cells with same content, because I had to replace an MSFlexGrid with MergeCells=flexMergeFree . 我曾经以类似的方式实现了一个渲染器,该渲染器将具有相同内容的相邻单元格合并,因为我必须MergeCells=flexMergeFree替换MSFlexGrid

Four drawbacks I know: 我知道四个缺点:

  • you have to always get the correct amount of display:none for your colSpan and rowSpan. 您必须始终获得正确的显示量:colSpan和rowSpan没有显示。
  • you can't use it easily with special columns (numbercolumns, datecolumns, checkcolumns), because you override their normal renderer. 您不能在特殊列(数字列,日期列,检查列)中轻松使用它,因为您会覆盖其常规渲染器。
  • your data has to be in a "record with primitive values" form, so when you load the store you would have to walk through the tree and generate the records. 您的数据必须采用“带有原始值的记录”形式,因此,在加载商店时,您将必须遍历树并生成记录。
  • will no longer work in ExtJS6; 将不再在ExtJS6中工作; not sure about ExtJS 5. 不确定ExtJS 5。

Solution two: Nested grids 解决方案二:嵌套网格

You can easily render a grid into a grid's RowExpander plugin . 您可以轻松地将网格渲染到网格的RowExpander插件中

plugins: [{
    ptype: "rowexpander",
    rowBodyTpl: ['<div id="SessionInstructionGridRow-{ClientSessionId}" ></div>']
    listeners:{
        expandbody:function() {
            var targetId = 'SessionInstructionGridRow-' + record.get('ClientSessionId');
            if (Ext.getCmp(targetId + "_grid") == null) {
                var sessionInstructionGrid = Ext.create('TS.view.client.SessionInstruction', {
                    renderTo: targetId,
                    id: targetId + "_grid"
                });
                rowNode.grid = sessionInstructionGrid;
                sessionInstructionGrid.getEl().swallowEvent(['mouseover', 'mousedown', 'click', 'dblclick', 'onRowFocus']);
                sessionInstructionGrid.fireEvent("bind", sessionInstructionGrid, { ClientSessionId: record.get('ClientSessionId') });
            }
        }
    }
}],

The main drawback being that it does look like a grid inside a grid, not like a single grid with rowSpan and colSpan; 主要缺点是,它看起来确实像网格中的网格,而不像具有rowSpan和colSpan的单个网格; so it is nowhere near your screenshot. 因此它离您的屏幕快照不远。 But this is how I implemented display of content of fields containing arrays just today. 但这就是我今天才实现显示包含数组的字段内容的方式。 You could as well render a propertygrid into the rowExpander, if you want to show structured data (objects). 如果要显示结构化数据(对象),也可以将propertygrid渲染到rowExpander中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM