Closed ghiscoding closed 2 months ago
Hi, I've hit upon this issue a long time ago, the children array didn't get reset when recreating the tree. Fixed it via this patch.
diff --git a/node_modules/@slickgrid-universal/common/dist/esm/services/utilities.js b/node_modules/@slickgrid-universal/common/dist/esm/services/utilities.js
index 2e9b2f9..d737958 100644
--- a/node_modules/@slickgrid-universal/common/dist/esm/services/utilities.js
+++ b/node_modules/@slickgrid-universal/common/dist/esm/services/utilities.js
@@ -140,7 +140,10 @@ export function unflattenParentChildArrayToTree(flatArray, options) {
const roots = []; // items without parent which at the root
// make them accessible by guid on this map
const all = {};
- inputArray.forEach((item) => all[item[identifierPropName]] = item);
+ inputArray.forEach((item) => {
+ all[item[identifierPropName]] = item;
+ delete item[childrenPropName];
+ });
// connect childrens to its parent, and split roots apart
Object.keys(all).forEach((id) => {
const item = all[id];
@jano-kucera I'm not sure why you're referencing this when it's already been fixed and pushed to production? If there's another problem or if this is a better fix than mine, then please contribute a fix as a new pull request so that it can benefit everyone. Thanks
Actually I wonder if the delete prop has better perf compare to the .findIndex()
that I added in the latest fix I made, it's probably faster and if so then a PR would be nice. It might also be good to compare perf with console.time on a large dataset if possible.
cc @tnaum-ms
Also note that another user also found and provided another perf improvement related to Tree Data in this PR #1670 that I just merged today (to be released soon)
From the code snippet, your fix does not handle removing children - that's why I commented :). If I find time I will measure it, but I believe deleting a prop will always be faster than an index lookup.
@jano-kucera then a Pull Request would be welcome to fix it, thanks
Also I just realized a big problem in the implementation, you access the id
field, not the identifierPropName
- thus if you use any other property name for IDs (even from gridOptions), you end up children replacing each other.
Discussed in https://github.com/ghiscoding/slickgrid-universal/discussions/1655