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

Menu RemoteData Binding

Hi support,
I'm using the Syncfusion javascript controls with a Yii2 Framework as backend.
I have used your menu template example which uses var data =

{
category: {
value: 'Products',
count: '30+'
},
options: [
{ value: 'JavaScript', url: 'javascript' },
{ value: 'Angular', url: 'angular' },
{ value: 'ASP.NET Core', url: 'core' },
{ value: 'ASP.NET MVC', url: 'mvc' }
]
},

Menu options are set with
var menuOptions = {
items: data,
fields: {
text: ['category', 'value'],
children: ['options']
},
template: '#menuTemplate'
};

This works without problems.
Now I want to load this data with remote binding. But I don't know how to do this.

I have successfully used the data binding with a grid like this:

var data = new ej.data.DataManager({
url: 'http://localhost/rubw/basic/web/athletsrest',
adaptor: new ej.data.WebApiAdaptor()
});

var grid = new ej.grids.Grid({
dataSource: data,
columns: [
{ field: 'name', headerText: 'Name', textAlign: 'Right', width: 120, type: 'string' },
{ field: 'surname', width: 140, headerText: 'Surname', type: 'string' },
{ field: 'gender', headerText: 'gender', textAlign: 'Right', width: 120, format: 'string' },
{ field: 'lightweight', headerText: 'lightweight', width: 140, format: 'string' }
],
allowPaging: true,
pageSettings: {pageSize: 20, pageCount: 8, pageSizes: true},
});

But this does not work with the menu control.

Can you please give me a hint how to achieve this?

TIA Stephan

3 Replies

VK Vinoth Kumar Sundara Moorthy Syncfusion Team July 30, 2019 01:27 PM UTC

Hi Stephan, 
 
Good day to you. 
 
We have checked your requirement “How to bind the remote data in menu component” and we have prepared the sample to bind the remote data in the menu component for your convenience.  
 
 
Could you please check the above sample and get back to us for further assistance on this? 
 
Regards, 
Vinoth Kumar S 



SS Stephan Schrade July 30, 2019 08:38 PM UTC

Many thanks for your answer, but the query is very complex and I don't understand it.
I don't need a query, I just want to get all the data form the backend.
And the I don't understand the syntax of the right hand side of the "items" property.

Your backend generates a response with XML, I'm using JSON.
And I don't know how the structure of the response has to be set in order to work with the menu component.
I thought it hast to be the same like the variable data (screenshot in my initial question).

And if I use
var menuOptions = {
items: ((<Object[]>e.result) as { [key: string]: Object }[]),
fields: {
text: ['category', 'value'],
children: ['options']
},
template: '#menuTemplate'
};
I do get an syntax error within Safari and Mozilla because of the bracket (<)


VK Vinoth Kumar Sundara Moorthy Syncfusion Team August 1, 2019 04:03 PM UTC

Hi Stephen, 
 
Good day to you. 
 
Query 1: And the I don't understand the syntax of the right-hand side of the "items" property. 
 
We would like to let you know that right hand side of items property defines key value pair of objects. 
 
Query 2: Your backend generates a response with XML, I'm using JSON. And I don't know how the structure of the response has to be set in order to work with the menu component. 
 
Please check our JSON format data source in the below link, 
 
For your convenience, we have prepared a sample by using the Json data source. Please check the sample in below 
 
Query 3: I do get a syntax error within Safari and Mozilla because of the bracket (<) 
 
We have checked your reported issue in Mozilla, but we are not able to reproduce it. Could you please provide more details to replicate the issue? 
 
Regards, 
Vinoth Kumar S 


Loader.
Live Chat Icon For mobile
Up arrow icon