[英]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: 我知道四个缺点:
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.