javascript - SAPUI5 TreeTable - Node expanding behavior -
problem is:
i'm trying keep nodes in treetable expanded, when i'm adding rows @ runtime. default behavior of treetable is, when happens it, get's rendered again , nodes collapsed.
the api provides methods keep first level expanded, keep lower level nodes expanded, too. how can achieve that?
before adding row:
after adding row:
expectation:
[edit]
i've tried to right behavior using expand(irowindex), in case, lifecycle of treetable (adding content, getting rerendered), not helpful.
what i'm doing:
i'm trying add data using drag&drop functions. soon, we're trying add content specific position treetable, have right positions of parent , child elements. unfortunately second+ level hidden after adding said content , messes drag&drop, because table rows have different ids, when they're collapsing.
basically need treetable function ."setexpandfirstlevel(true)" other levels.
it's bit dirty, use treetable
's expand(irowindex)
method calling while iterating on every row item
edit: have created working example (see below), showing don't need use rowid or add control dom. thing drag/drop should add child node selected node using model only.
in effect, expand(rowindex)
works fine, visible rows instantly expanded (but see nb2 below)
nb1: simplicity sake, have not created full drag/drop example, clicking 'add child node' button should mimic 'drop' event.
nb2: apparently there bug in expand
method: expands visible tree items. items after scroll 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 1 obj.data.push(onew); this.getview().getmodel().setproperty(ocontext.getpath(), obj); this._doexpandall(); }, _doexpandall : function() { var ottbl = this.getview().byid("tbl"); (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>
Comments
Post a Comment