We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Event "nodeExpanding" fired twice?

Hi there,

Actually I wanted to use the DataManager for loading my remote data but I did not manage to lazy load children into their parents. So I tried a custom approach. The below code works but it seem to fire twice. Of course I could ignore the second shot with some hacking but I´m curious what causes this. If anyone has an idea how I can fix this or how I get the WebApiAdapter working that would be great. I´m thankful for any advice. 


import './RemotePane.css';
import { ItemDirective, ItemsDirective, ToolbarComponent, TreeViewComponent } from '@syncfusion/ej2-react-navigations';
import { useEffect, useState } from 'react';

function RemotePane() {

  let tree;
  const [data, setData] = useState([]);

  const loadRootData = dir => {
    if(!dir) dir = ".";
    fetch('http://localhost:8080/ListFolders')
      .then(res => res.json())
      .then(res => setData(res.Items));
  }

  const loadChildData = node => {
    const target = node.nodeData.text;
    fetch('http://localhost:8080/ListFolders?parent='+target)
      .then(res => res.json())
      .then(res => {
        console.log(res)
        tree.addNodes(res.Items, target)
      });
  }

  useEffect(() => {
    loadRootData();
  }, []);

  const fields = { dataSource: data, id: 'name', text: 'name', iconCss: 'icon', hasChildren: 'hasChildren'};

  return (
    <>
      <div className='header-remote-pane'>Remote Drive</div>
      <ToolbarComponent id='toolbar'>
        <ItemsDirective>
          <ItemDirective prefixIcon='e-icons e-arrow-down' text="Download" />
          <ItemDirective prefixIcon='e-icons e-close-6' text="Delete" />
          <ItemDirective prefixIcon='e-icons e-folder' text="New Folder" />
        </ItemsDirective>
      </ToolbarComponent>
      <TreeViewComponent fields={fields} nodeExpanding={node => loadChildData(node)} ref={elm => tree = elm} />
    </>
  );
}

export default RemotePane;

1 Reply

SA SureshRajan Alagarsamy Syncfusion Team March 1, 2023 03:38 PM UTC

Hi Martin,


Greetings from Syncfusion support.


From your shared details and code snippet, we understand that you are facing an issue with nodeExpanding event in TreeView. We have prepared a sample in which we have obtained data through an XML request from a provider and bound the “nodeExpanding” event. We tested the sample by expanding the nodes and did not face any issues similar to the one you reported.


Find the attached sample and provider file for your reference.


Sample : https://stackblitz.com/edit/angular-rhrcs2?file=src%2Fapp.component.ts


Service provider: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication-1047265598.zip


Check out the shared details and if we have misunderstood your query, please let us know and try to replicate the issue in our shared sample itself. Also, share us the package version used at your end. This will help us to validate the issue with more efficiency and provide a resolution that meets your requirements.


Regards,
Suresh.


Loader.
Live Chat Icon For mobile
Up arrow icon