Smart UI Components & Libraries – Grid, Scheduler, Gantt, Kanban for Angular, React, Next.js, Vue, Blazor, JavaScript › Forums › General Discussions › DataAdapter Second Level json datafields
Tagged: dataAdapter json, htmlelements json, json data
- This topic has 8 replies, 2 voices, and was last updated 5 years, 5 months ago by admin. 
- 
		AuthorPosts
- 
		
			
				
May 19, 2020 at 12:15 pm #100759admin KeymasterHello, 
 I have a question concerning data fields in the dataAdapter. I have an json object used as source by the adapter that looks like this:{ text: 'text', object: { text2:'text2' } }I didn’t found an opportunity to select text2 as datafield. In JQWidgets there was away to map a datafield to solve this problem. Is there something like that in Smart Html Elements? May 19, 2020 at 1:36 pm #100760admin KeymasterHi Gerhard Seemann, 
 Have you tried it by defining the dataFields array as in our jqxDataAdapter like that { name: …, map: …. } The map field defines the sub property mapping.
 Regards,
 Peter
 Smart UI Team
 https://www.htmlelements.com/May 20, 2020 at 10:14 am #100763admin KeymasterHi Peter, 
 defining the dataFields like that didn’t work for me in the Smart.DataAdapter. Even without the mapping. The only way it worked for me wasdataFields: [ 'name:type', 'name:type' ]But I don’t see a way to do the mapping defining it like that. 
 
 Regards,
 GerhardMay 20, 2020 at 10:35 am #100764admin KeymasterHi Gerhard, 
 Did you follow my suggestion? Could you share codepen sample which shows how you tried to define a dataAdapter with dataFields mapping?
 Regards,
 Peter
 Smart UI Team
 https://www.htmlelements.com/May 20, 2020 at 11:23 am #100765admin KeymasterHi, 
 yeah I followed your suggestion. I tried it without mapping and with mapping. Both doesn’t work.
 Here it is without mapping:
 https://codepen.io/captaingerhard/pen/ExVGEKW?editors=0010
 And here it is with mapping:
 https://codepen.io/captaingerhard/pen/WNQLzyQ?editors=0010
 
 Regards,
 GerhardMay 20, 2020 at 12:04 pm #100766admin KeymasterHi Gerhard, 
 You can use this:dataSource: new Smart.DataAdapter({ dataSource: data, dataFields: [ {name: 'text1', dataType: 'string'}, {name: 'object', dataType: 'string'} ] }), columns: [ { label: 'Text 1', dataField: 'text1' }, { label: 'Object', dataField: 'object' }, ]Regards, 
 Peter
 Smart UI Team
 https://www.htmlelements.com/May 20, 2020 at 12:19 pm #100767admin KeymasterHi Peter, 
 thank you! Now I can define it like that. But it doesn’t solve my mapping problem.
 https://codepen.io/captaingerhard/pen/WNQLzyQ?editors=0010
 Is the attribute ‘map’ wrong, too?
 
 Regards,
 GerhardMay 20, 2020 at 12:25 pm #100768admin KeymasterHi Gerhard, 
 With mapping, you can use:var data = [ {text1: 'abcde', object: {num1: 123}}, {text1: 'abcde', object: {num1: 123}}, {text1: 'abcde', object: {num1: 123}}, {text1: 'abcde', object: {num1: 123}}, {text1: 'abcde', object: {num1: 123}}];Smart('#grid', class { get properties() { return { dataSource: new Smart.DataAdapter({ mapChar: '.', dataSource: data, dataFields: [ {name: 'text1', dataType: 'string'}, {name: 'num1', map: 'object.num1', dataType: 'number'} ] }), columns: [ { label: 'Text 1', dataField: 'text1' }, { label: 'Number', dataField: 'num1' }, ] } } }); Hope this helps. 
 Regards,
 Peter
 Smart UI Team
 https://www.htmlelements.com/May 20, 2020 at 12:39 pm #100769admin KeymasterHi, 
 yes that helped. Thank you a lot!
 Best regards,
 Gerhard
- 
		AuthorPosts
- You must be logged in to reply to this topic.