简体   繁体   English

SAPUI5 TreeTable - 节点扩展行为

[英]SAPUI5 TreeTable - Node expanding behavior

Problem is: 问题是:

I'm trying to keep the nodes in a TreeTable expanded, when I'm adding rows at runtime. 当我在运行时添加行时,我正在尝试扩展TreeTable中的节点。 Default behavior of a TreeTable is, when something happens with it, it get's rendered again and all nodes are collapsed. TreeTable的默认行为是,当它发生某些事情时,它会再次渲染并且所有节点都被折叠。

The API only provides methods to keep the first level expanded, but I like to keep lower level nodes expanded, too. API仅提供保持第一级扩展的方法,但我也希望扩展较低级别的节点。 How can I achieve that? 我怎样才能做到这一点?

Before adding a row: 在添加行之前:

之前

After adding a row: 添加一行后:

后

Expectation: 期望:

expectiation

[EDIT] [编辑]

I've already tried to to get the right behavior by using expand(iRowIndex), but in my case, the lifecycle of that TreeTable (Adding content, getting rerendered), is not helpful. 我已经尝试通过使用expand(iRowIndex)来获得正确的行为,但在我的情况下,TreeTable的生命周期(添加内容,获得重新呈现)是没有用的。

What I'm doing: 我在做什么:

I'm trying to add data by using Drag&Drop functions. 我正在尝试使用拖放功能添加数据。 As soon, as we're trying to add content to a specific position into the TreeTable, we have to get the right positions of the parent and child elements. 很快,当我们尝试将内容添加到TreeTable中的特定位置时,我们必须获得父元素和子元素的正确位置。 Unfortunately the second+ level is hidden after adding said content and that messes with my Drag&Drop, because the table rows have different IDs, when they're collapsing. 不幸的是,在添加所述内容之后隐藏了第二个+级别,并且我的拖放会混淆,因为表格行在折叠时具有不同的ID。

Basically I need a TreeTable function like ."setExpandFirstLevel(true)" for all other levels. 基本上我需要一个TreeTable函数,如所有其他级别的“setExpandFirstLevel(true)”。

It's a bit dirty, but you could use the TreeTable 's expand(iRowIndex) method by calling it while iterating over every row item 它有点脏,但你可以通过调用它来迭代每个行项时使用TreeTableexpand(iRowIndex)方法


EDIT : I have created a working example (see below), showing you don't need to use the rowID or add any control to the DOM. 编辑 :我已经创建了一个工作示例(见下文),显示您不需要使用rowID或向DOM添加任何控件。 The only thing the drag/drop should do is add a child node to the selected node using the model only . 拖放操作应该做的唯一事情是仅使用模型将子节点添加到所选节点。
But in effect, the expand(rowIndex) works perfectly fine, all visible rows are instantly expanded (but see NB2 below) 但实际上, expand(rowIndex)工作得非常好,所有可见行都会立即展开(但请参见下面的NB2)

NB1: for simplicity sake, I have not created a full drag/drop example, but clicking the 'add child node' button should mimic the 'drop' event. NB1:为简单起见,我没有创建完整的拖放示例,但单击“添加子节点”按钮应该模仿'drop'事件。

NB2: Apparently there is a bug in the expand method: It only expands the visible tree items. NB2:显然, expand方法中存在一个错误:它只扩展可见树项。 Any items after the scroll are not expanded... 滚动后的任何项目都不会展开...

 sap.ui.controller("view1.initial", { onInit : function(oEvent) { var oModel = new sap.ui.model.json.JSONModel(); oModel.setData({ data : [ { name : "node1", description : "Lorem ipsum dolor sit amet", data : [ { name : "node1.1", description : "Cras pretium nisl ac ex congue posuere" }, { name : "node1.2", description : "Consectetur adipiscing elit", data: [ { name : "node1.2.1", description : "Maecenas accumsan ipsum diam" } ] }, { name : "node1.3", description : "Sed tristique diam non imperdiet commodo" }, { name : "node1.4", description : "Consectetur adipiscing elit", data: [ { name : "node1.4.1", description : "Maecenas accumsan ipsum diam", data: [ { name : "node1.4.1.1", description : "Maecenas accumsan ipsum diam", data: [ { name : "node1.4.1.1.1", description : "Maecenas accumsan ipsum diam", data: [ { name : "node1.4.1.1.1.1", description : "Maecenas accumsan ipsum diam" } ] } ] } ] } ] }, { name : "node1.5", description : "Sed tristique diam non imperdiet commodo" }, { name : "node1.6", description : "Consectetur adipiscing elit", data: [ { name : "node1.6.1", description : "Maecenas accumsan ipsum diam" } ] }, { name : "node1.7", description : "Sed tristique diam non imperdiet commodo" }, ] }, ] }); this.getView().setModel(oModel); }, onAfterRendering : function() { this._doExpandAll(); }, addNode : function(oEvent) { var oContext = oEvent.getSource().getBindingContext(); var obj = oContext.getObject(); var oNew = { name : "New node", description : "New description"}; if (!obj.data) obj.data = []; //if no child array, create empty one obj.data.push(oNew); this.getView().getModel().setProperty(oContext.getPath(), obj); this._doExpandAll(); }, _doExpandAll : function() { var oTTbl = this.getView().byId("tbl"); for (var i=0; i<oTTbl.getRows().length; i++) { oTTbl.expand(i); } } }); var app = new sap.m.App({}); var oView = sap.ui.xmlview({ viewContent: jQuery("#view1").html() }); app.addPage(oView); app.placeAt("uiArea"); 
 <script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-xx-bindingSyntax="complex" data-sap-ui-libs="sap.m"></script> <script id="view1" type="ui5/xmlview"> <mvc:View controllerName="view1.initial" xmlns:t="sap.ui.table" xmlns="sap.ui.commons" xmlns:mvc="sap.ui.core.mvc" > <t:TreeTable id="tbl" rows="{path:'/',parameters:{arrayNames:['data']}}" visibleRowCount="10"> <t:columns> <t:Column> <t:label><Label text="name" /></t:label> <t:template><TextView text="{name}" /></t:template> </t:Column> <t:Column> <t:label><Label text="description" /></t:label> <t:template><TextView text="{description}" /></t:template> </t:Column> <t:Column> <t:label><Label text="" /></t:label> <t:template><Button text="Add child node" press="addNode"/></t:template> </t:Column> </t:columns> </t:TreeTable> </mvc:View> </script> <div id="uiArea"></div> 

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

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