Winter 18 <lightning:datatable> does not get values from a parent record
There is no way today to access data like foo.bar.baz
. The consumer of datatable has to flatten their data(server side or client side). Its a valid use case to consider.
I just hit the same problem. The way I resolved it was by modifying the response and adding an additional key->value pair for each record before I assign it to the attribute. You should be able to get the idea from this snippet (I tailored it to suit your code, so you might need to make some modifications before you get it working):
var commaDelimitedFieldNamesArray = commaDelimitedFieldNames.split(',');
var data = response.getReturnValue();
// Go through each field
for (var i = 0; i < commaDelimitedFieldNamesArray.length; i++)
{
var fieldName = commaDelimitedFieldNamesArray[i];
// If the field name contains a '.' (dot), it's a relationship field (e.g. Account.Name)
if (fieldName.indexOf('.') != -1)
{
// Break up the levels of parenthesis [Account, Name]
var relationshipFields = fieldName.split('.');
// Go through each record from the response
for (var record in data)
{
// Grab the field value (first level), should be an object (record.Account)
var fieldValue = record[relationshipFields[0]];
// Keep going until you come to the last nested object - that should have the actual value (ultimately record.Account.Name)
for (var j = 1; j < relationshipFields.length; j++)
{
if (fieldValue && relationshipFields[j])
{
fieldValue = fieldValue[relationshipFields[j]];
}
}
// Set another property on the record object with the actual value (record[Account.Name] = 'Actual Value')
record[fieldName] = fieldValue;
}
}
}
component.set("v.mydata", data);