Hello everyone, I'm currently working on a complex TreeView, with a flat data binding, and I have the necessity to pass to the backend the whole tree ordered "as is" after a drag and drop operation is performed:
I prepared a starting StackBlitz at: https://stackblitz.com/edit/angular-w8t3pg?file=app/app.component.ts
Here's what I'd like to happen:
1) user drags C above A, create an array (or modify the existing one (nodes)) like this:
[
{ id: 3, name: 'C', parent: null, isfather: true },
{ id: 5, name: 'D', parent: 3, isfather: true },
{ id: 6, name: 'E', parent: 5, isfather: false},
{ id: 4, name: 'F', parent: 5, isfather: false },
{ id: 2, name: 'A', parent: null, isfather: true },
{ id: 1, name: 'B', parent: 2, isfather: false },
{ id: 7, name: 'G', parent: null, isfather: true },
{ id: 8, name: 'H', parent: 7, isfather: false },
{ id: 9, name: 'J', parent: 7, isfather: false },
];
2) then, the user moves B inside E (E sees its flag isfather changed to true, whereas A to false since it doesn't have any child anymore)
[
{ id: 3, name: 'C', parent: null, isfather: true },
{ id: 5, name: 'D', parent: 3, isfather: true },
{ id: 6, name: 'E', parent: 5, isfather: true },
{ id: 1, name: 'B', parent: 5, isfather: false },
{ id: 4, name: 'F', parent: 5, isfather: false },
{ id: 2, name: 'A', parent: null, isfather: false },
{ id: 7, name: 'G', parent: null, isfather: true },
{ id: 8, name: 'H', parent: 7, isfather: false },
{ id: 9, name: 'J', parent: 7, isfather: false },
];
Is it possible to do so? At the moment I'm trying with this solution (using my code and not the one in the example):
<kendo-treeview
#tree
gdArea="checklisttree"
[navigable]="false"
[nodes]="nodes"
kendoTreeViewFlatDataBinding
textField="id"
idField="id"
parentIdField="idlink"
kendoTreeViewExpandable
[expandedKeys]="expandedKeys"
expandBy="id"
kendoTreeViewDragAndDrop
kendoTreeViewDragAndDropEditing
(nodeDrop)="getNodesInOrder($event)"
(addItem)="log('addItem', $event)"
(removeItem)="log('removeItem', $event)"
kendoTreeViewSelectable
[(selectedKeys)]="selectedKeys"
(selectionChange)="nodeSelectionChangeHandler($event)"
>
<ng-template kendoTreeViewNodeTemplate let-dataItem>
{{ '(id = ' + dataItem.id + '), (title = ' + dataItem.title + ' )' }}
</ng-template>
<ng-template
kendoTreeViewDragClueTemplate
let-action="action"
let-sourceItem="sourceItem"
let-destinationItem="destinationItem"
let-text="text"
>
<span class="k-drag-status k-icon" [ngClass]="getDragStatus(action, sourceItem, destinationItem)"></span>
<span>{{ text }}</span>
</ng-template>
</kendo-treeview>
With the idea of using the arrays inside the editService like this:
getNodesInOrder($ev? TreeitemDragEvent): void {
const rootNodes: any[] = (this.tree as any).editService.flatBinding.filterData; //list of the root elements
const nodes = []; // I'd like to use this to push the various children in order I miss how to do this with recursive function
rootNodes.forEach(node => {
node.dataItem.isfather = node.children.length > 0;
nodes.push(node.dataItem);
// recursive call here?
})
console.log(nodes);
}
Here's how the editService.flatBinding.filterData looks like:

Feel free to edit the stackblitz to make me understand how to do this... Thanks in advance
interface FlatBindingData { children: FlatBindingData[]; dataItem: I.CheckListItems; visible: boolean; parent: FlatBindingData; index: string; }; getNodesInOrder(ev?: TreeItemDragEvent): void { const source = ev.sourceItem.item; const sourceIndex = source.index; const dest = ev.destinationItem.item; const destIndex = dest.index; if (ev) { // Prevent droppping node on itself if (sourceIndex === destIndex) { return; } // Prevent dropping node on one of his chldren (they'll share the initial portion of their index) if (destIndex.substring(0, sourceIndex.length) === sourceIndex) { return; } } this.tmpArr = []; const rootNodes: FlatBindingData[] = (this.tree as any).editService.flatBinding.filterData; this.recursiveFunc(rootNodes); } recursiveFunc(nodes: FlatBindingData[]) { nodes.forEach(node => { const hasChildren = node.children.length > 0; node.dataItem.isfather = hasChildren; this.tmpArr.push(node.dataItem); if (!hasChildren) return this.recursiveFunc(node.children); }) }