sap.m.Tree - JsonModel - Filter - arrayNames
OpenUI5 version: Detected in 1.48, but presumably in all versions since 1.44
Browser/version (+device/version): All browsers and devices
URL (minimal example if possible): https://embed.plnkr.co/bCOxJgLiQ6YRgKjhMsdq/
Steps to reproduce the problem: If you create hierachical json model with arrays
new JSONModel([ {key:"node1", text:"bla", children:[...]},
{key:"node2", text:"moo", children:[...]} ]
and you assign this to a Tree:
items:{path:'/', parameters{ arrayName:['children']} }
Filtering won't work anymore.
The reason fir this lies in the ClientTreeBinding method getNodeContexts

If your node is an array "aChildArray = oNode[sArrayName];" will not work. this assumes that your model is a hierarchical object, instead of an array.
if however you could add
if(oNode instanceof Array){
oNode.forEach(function(oItem){
aChildArray = oItem[sArrayName];
...
})
Than filtering would also work on Array based json models.
PS, this issue is also in SAPUI5
small update, with a solution: https://embed.plnkr.co/bCOxJgLiQ6YRgKjhMsdq/
I made an override of the ClientTreeBinding.prototype.getNodeContexts
ClientTreeBinding.prototype.getNodeContexts = function (oContext, iStartIndex, iLength) {
if (!iStartIndex) {
iStartIndex = 0;
}
if (!iLength) {
iLength = this.oModel.iSizeLimit;
}
var sContextPath = this._sanitizePath(oContext.getPath());
var aContexts = [],
that = this,
oNode = this.oModel._getObject(sContextPath),
aArrayNames = this.mParameters && this.mParameters.arrayNames,
aChildArray;
if (oNode) {
if (Array.isArray(aArrayNames)) {
aArrayNames.forEach(function (sArrayName) {
if (Array.isArray(oNode)) {
that._saveSubContext(oNode[i], aContexts, sContextPath, i + "/" + sArrayName);
for(var i=0; i< oNode.length; i++) {
aChildArray = oNode[i][sArrayName];
that._saveSubContext(oNode[i], aContexts, sContextPath, i );
if (aChildArray instanceof Array ) {
for (var j = 0; j < aChildArray.length; j++) {
that._saveSubContext(aChildArray[j], aContexts, sContextPath, i + "/" + sArrayName + "/" + j);
};
}
};
} else {
aChildArray = oNode[sArrayName];
if (aChildArray) {
jQuery.each(aChildArray, function (sSubName, oSubChild) {
that._saveSubContext(oSubChild, aContexts, sContextPath, sArrayName + "/" + sSubName);
});
}
}
});
} else {
jQuery.sap.each(oNode, function (sName, oChild) {
if (Array.isArray(oChild)) {
oChild.forEach(function (oSubChild, sSubName) {
that._saveSubContext(oSubChild, aContexts, sContextPath, sName + "/" + sSubName);
});
} else if (typeof oChild == "object") {
that._saveSubContext(oChild, aContexts, sContextPath, sName);
}
});
}
}
this._applySorter(aContexts);
this._setLengthCache(sContextPath, aContexts.length);
return aContexts.slice(iStartIndex, iStartIndex + iLength);
};
Be so kind to validate and include in the next patches :-)
Hi FiddleBe, your findings have been forwarded to the responsible dev team with incident 1780511277.
Regards, Mihail.
Hi @FiddleBe,
Thank you for you report and your great analysis! I was able to reproduce this bug.
However, I found an easier fix by skipping the arrayNames check if we are dealing with an array of nodes instead of a single one. We couldn't check against an array name in that case anyway (as we don't want to load the children those nodes).
I have forked your Plunk and updated it with my proposed change: https://embed.plnkr.co/szUl1TyVR1WGy1E38p83/
We are currently preparing this change internally. Please let me know if you have concerns or questions.
Also, please let me know wether you need this fix in any of the already released code lines (like 1.52).
Thanks!
Ahh, so if the node IS an array, you first store the subcontext of the node itself, and then recursively process each item in the array. that's an elegant fix. and it solves my (non-prio) issue of having duplicate subcontexts
a second issue I faced after posting my proposal, was the iSizeLimit. I had a tree with 200 items, and apparently there's a default iSizeLimit of 100. I overcame that issue by setting the iSizeLimit directly on my model to 99999. But wouldn't it be better if there was a parameter that let's you ignore any sizelimit? (eventhough I agree that performance can be severly affected)
Thanks for taking this up
PS: can you also update the doco of the sap.m.tree with the parameters? I only found out about them by diving deep into the debug-code.
PPS: if a patch can be made available for 1.46, 1.48, 1.50 and up, that would be great! We have a couple of projects still on 1.46 because of compatibility issues
Ahh, so if the node IS an array, you first store the subcontext of the node itself, and then recursively process each item in the array.
Correct 👍
a second issue I faced after posting my proposal, was the iSizeLimit. I had a tree with 200 items, and apparently there's a default iSizeLimit of 100.
I had a brief look into this. It appears to work correctly for the sap.ui.table.TreeTable, but not for sap.m.Tree where the behavior changed with commit https://github.com/SAP/openui5/commit/82a4586587fb4e2168f7a5a2c9effe3cb1de6ac9 to solve an issue with ODataModels.
In this scenario you are using a JSONModel as well, correct? If yes, could you please create a new issue for this? Thanks.
But wouldn't it be better if there was a parameter that let's you ignore any sizelimit?
I would opt to ignore any size limit for all client models actually.
can you also update the doco of the sap.m.tree with the parameters? I only found out about them by diving deep into the debug-code.
Could you please create another issue for this as well? sap.m.Tree is actually owned by another team.
if a patch can be made available for 1.46, 1.48, 1.50 and up, that would be great! We have a couple of projects still on 1.46 because of compatibility issues
Apparently, 1.46 is out of maintenance (see OpenUI5 Versions Maintenance Status).
If you are not using the 1.44 long term release, I guess the best I can offer you is 1.48, 1.50 and >=1.52. What do you think?
I'll log 2 separate issues for the doco and the sizelimit
Okay for the supported versions. I'll propose internally to upgrade our UI5 version to 1.48
Thanks. I'll let you know once the fix got merged into all code lines. But I think there won't be a new patch release before next year.
We slightly reworked the change to make it easier to understand what's happening. I successfully tested it with your Plunk.
The change is now merged into master, 1.52, 1.50 and 1.48. It will be part of one of the upcoming releases of each code line.
Please let us know in case you have questions or if the issue still persists.
this problem still seems to be happening in SAPUI5... i can solve it by applying filtering from the controller instead of the view.... (in the view the filter has no effect, due to arrayNames)
oOutcomeTreeTable.getBinding("rows").filter(
new Filter({
path: "_sOperation",
operator: "NE",
value1: "DELETE",
})
);