JavaScript UI Libraries & Blazor Components Suite – Smart UI › 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 4 years, 6 months ago by admin.
-
AuthorPosts
-
May 19, 2020 at 12:15 pm #100759adminKeymaster
Hello,
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 #100760adminKeymasterHi 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 #100763adminKeymasterHi 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 #100764adminKeymasterHi 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 #100765adminKeymasterHi,
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 #100766adminKeymasterHi 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 #100767adminKeymasterHi 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 #100768adminKeymasterHi 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 #100769adminKeymasterHi,
yes that helped. Thank you a lot!
Best regards,
Gerhard -
AuthorPosts
- You must be logged in to reply to this topic.