Skip to content

Commit

Permalink
fix: treeview expand child nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
conflictboy committed Jan 22, 2025
1 parent af2dc7a commit aa4c2ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets/css/datagrid.css
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
margin-top: -9px
}

[data-datagrid-name] .datagrid-tree .datagrid-tree-item.has-children > .datagrid-tree-item-children {
[data-datagrid-name] .datagrid-tree .datagrid-tree-item.has-children > .datagrid-tree-item-children:not(.showed) {
display: none
}

Expand Down
11 changes: 10 additions & 1 deletion assets/plugins/features/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ export class TreeViewPlugin implements DatagridPlugin {
datagrid.ajax.addEventListener("success", ({detail: {payload}}) => {
if (payload._datagrid_tree) {
const id = payload._datagrid_tree;
const rowBlock = document.querySelector(`.datagrid-tree-item[data-id="${id}"]`);
const childrenBlock = document.querySelector(`.datagrid-tree-item[data-id="${id}"] .datagrid-tree-item-children`);
if (childrenBlock) {
childrenBlock.classList.add('loaded');
if (childrenBlock.classList.contains('showed')) {
childrenBlock.innerHTML = '';
childrenBlock.classList.remove('showed');
rowBlock.querySelector(`a.chevron`).style.transform = "rotate(0deg)";
return;
}

childrenBlock.classList.add('showed');
rowBlock.querySelector(`a.chevron`).style.transform = "rotate(90deg)";
const snippets = payload.snippets;
for (const snippetName in snippets) {
const snippet = snippets[snippetName];
Expand Down

0 comments on commit aa4c2ae

Please sign in to comment.