Is there a way for one to map data from a remote datasource using a function? For example consider the following column structure -
columns: [ { headerText: "ID", key: "id", dataType: "number", width: "50px" }, { headerText: "Name", key: "name", dataType: "string", width: "125px" }, { headerText: "apartment", key: "", dataType: "string", width: "125px" },
{ headerText: "homephone", key: "", dataType: "string", width: "125px" },
{ headerText: "cellphone", key: "", dataType: "string", width: "125px" },
]
Now consider the following JSON response -
[{
id: "546df5a6bb1a4fde4508a13d
name: "Bob"
details: [{
type: "address",
moredetails: {
apartment: 900,
street: "Bay"
} ,
{
type: "phone",
home: 900455213,
cell: 500987276
}
}]
I wish to map the cellphone, homephone and apartment columns using conditional mapping so that the key would depend on the 'type' of a specific detail. How can i do this?
Hello,
I'm just following up to see if you need any further assistance with this issue. If so please let me know.
Hello Adil,
For every column you can define a formatter function that will return the value you want to display in that column. I have prepared a sample demonstrating how this can be done. Please note the json format I used to populate the grid is this:
"details" : [{ "type": "address", "moredetails": { "apartment": 900, "street": "Bay" }},{ "type": "phone", "moredetails": { "home": 900455213, "cell": 500987276 }}],
The JSON response you have cited does not seem valid and will not work if you do not correct its format like the above mentioned. Please let me know if you have any further questions on the issue.