addSelectOnModel: function () {
var oModel = this.getView().getModel();
var oData = oModel.getData();
var aCategories = oData.catalog.clothing.categories;
var fSetSelect = function (aArray) {
for (var i = 0; i < aArray.length; i++) {
aArray[i].selected = false;
if (aArray[i].categories) fSetSelect(aArray[i].categories);
}
}(aCategories);
oModel.setData(oData);
return oModel;
}
onInit: function () {
var that = this;
var oModel = new JSONModel("model/Clothing.json");
oModel.attachRequestCompleted(function (oEvent) {
that.addSelectOnModel();
});
this.getView().setModel(oModel);
}
<mvc:View controllerName="selectnodetreetable.selectnodetreetable.controller.View" xmlns="sap.ui.table" xmlns:mvc="sap.ui.core.mvc"
xmlns:m="sap.m" xmlns:u="sap.ui.unified" xmlns:core="sap.ui.core" height="100%">
<m:Page showHeader="false" enableScrolling="false">
<m:content>
<TreeTable id="TreeTableBasic"
rows="{path:'/catalog/clothing', parameters: {arrayNames:['categories']}, events: { dataReceived: '.onDataReceived'} }" selectionMode="None"
enableSelectAll="false" ariaLabelledBy="title" class="sapUiMediumMargin">
<extension>
<m:OverflowToolbar>
<m:Title id="title" text="Clothing"/>
<m:ToolbarSpacer/>
<m:Button text="Collapse all" press="onCollapseAll"/>
<m:Button text="Collapse selection" press="onCollapseSelection"/>
<m:Button text="Expand first level" press="onExpandFirstLevel"/>
<m:Button text="Expand selection" press="onExpandSelection"/>
</m:OverflowToolbar>
</extension>
<columns>
<Column width="9rem">
<template>
<m:CheckBox selected="{selected}" select="onSelectCheckBoxTreeTable"/>
</template>
</Column>
<Column width="13rem">
<m:Label text="Categories"/>
<template>
<m:Text text="{name}" wrapping="false"/>
</template>
</Column>
onSelectCheckBoxTreeTable: function (oEvent) {
var oObject = {};
var oModel = oEvent.getSource().getParent().getModel();
oObject.path = oEvent.getSource().getBindingContext().sPath;
oObject.object = oModel.getObject(oObject.path);
if (oObject.object.categories !== undefined) {
//if is not leef
this.selectedTopDownModel(oObject);
if (!oObject.object.selected) {
var sPath = oObject.path;
this.selectedBottomUpModel(oObject, sPath);
}
} else {
//if is leef
var sPath = oObject.path;
this.selectedBottomUpModel(oObject, sPath);
}
}
selectedTopDownModel: function (oObject) {
var bSelected = oObject.object.selected;
var aElement = oObject.object.categories;
for (var i = 0; i < aElement.length; i++) {
if (aElement[i].edit || aElement[i].edit === undefined)
aElement[i].selected = bSelected;
if (aElement[i].categories !== undefined) {
var oElementObject = {
object: aElement[i]
};
this.selectedTopDownModel(oElementObject);
}
}
},
selectedBottomUpModel: function (oObject, sPath) {
var oModel = this.getView().getModel();
var aSplitPath = sPath.split("/");
aSplitPath.pop();
aSplitPath.pop();
sPath = aSplitPath.join('/');
var oParetnObject = oModel.getObject(sPath);
if (oParetnObject.selected && !oObject.selected) {
oParetnObject.selected = false;
this.selectedBottomUpModel(oParetnObject, sPath);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 |