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

Load variable with result form DataManager

Hi support,
I'm getting a little frustrated with the datamanager.

From your examples I think the following code should work:
var dataext = new ej.data.DataManager({
url: 'http://localhost/rubw2/basic/web/nav/navleft',
adaptor: new ej.data.WebApiAdaptor()
}).executeQuery(new ej.data.Query()).then((e) => {
datamanager = e.result;
});

But the variable datamanger is empty.

Result of localhost/rubw2/basic/web/nav/navleft is:
{"Items":[{"nodeId":"1","nodeText":"Home","url":"/home"},{"nodeId":"2","nodeText":"Athletes","url":"/athlets"}],"Count":1}

which does generate a nice tree view when I use the data manger without query and set the tree view property dataSource to the datamanger (variable dataext)

Regards,
Stephan










3 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team July 31, 2019 08:56 AM UTC

Hi Stephan, 

Thanks for contacting Syncfusion support. 

If you are using data manager for data binding then there is no necessary to perform the excuteQuery it automatically execute the query and bind the data to the component. If you are using the below way then it work as remote data binding for every actions(like paging, sorting) we have send the query and you need to handle it in server side. 

// if you are binding(dataext) like this then it considered as remote data  
var dataext = new ej.data.DataManager({ 
        url: '/api/Orders/', 
        adaptor: new ej.data.WebApiAdaptor() 
    }) 

<script> 
    var datamanager; 
    var dataext = new ej.data.DataManager({ 
        url: '/api/Orders/', 
        adaptor: new ej.data.WebApiAdaptor() 
    }).executeQuery(new ej.data.Query()).then((e) => { 
        datamanager = e.result; // if you bind datamanager for component then it considered as local data and its done the actions such as sort etc., in client side. 
        console.log(datamanager) 
    }); 
</script> 

We have checked with our end and we are able to get the datamanager (e.result did not empty). Please share more information regarding your requirement that will helpful for us to validate further at our end(also share the sample or code example). Also refer the below help documentation link for more information. 


Regards, 
Thavasianand S. 



SS Stephan Schrade July 31, 2019 07:31 PM UTC

Thank you for your quick answer.

I understand now, that
as e.result is generated in the anonymous function, the scope is local.
So I cant't get. the data to the "outside".
How can I achieve this? (I know this is more a javascript question than syncfusion related)

Or is there another way to get the pure received data (json reply) trough the DataManger without using a query?
Or do I have to do this without DataManager as all?

TIA
Stephan


DR Dhivya Rajendran Syncfusion Team August 1, 2019 12:20 PM UTC

Hi Stephan, 

Thanks for your update. 

You can declare global variable and assign the result(JSON) to the variable so that you can get the value outside of the scope. Please share more information about your requirement and share the component details whether did you used syncfusion component(like grid, treeview etc.,) or any other custom component.  
  
<script> 
    var datamanager; 
    var dataext = new ej.data.DataManager({ 
        url: '/api/Orders/', 
        adaptor: new ej.data.WebApiAdaptor() 
    }).executeQuery(new ej.data.Query()).then((e) => { 
        datamanager = e.result; // if you bind datamanager for component then it considered as local data and its done the actions such as sort etc., in client side. 
        console.log(datamanager) 
    }); 
</script> 
 
// you can bind datamanager(it contain the JSON result) to the component 

Note : If you don’t want to use data manager then you can make your own AJAX request and get the data from server. 

Regards, 
R.Dhivya  


Loader.
Live Chat Icon For mobile
Up arrow icon