You use Array.prototype.find to find the column based on the incoming fieldName:
var columns = cmp.get("v.columns"), // whatever you called the columns attribute
fieldName = event.getParam("fieldName"),
sortByCol = columns.find(column => fieldName === column.fieldName),
fieldLabel = sortByCol.label;
At this point, you have all the attributes from the column header (sortByCol
) and the field label, as you've asked for.
Your format is messed up. There should be two top-level objects, rows
and table
. The rows
key should contain keys that match the keyField
values for the table. Table messages themselves should be in the table
key.
{ rows:
{ a: { title: "...", messages: [...], fieldNames: [...] },
b: { title: "...", messages: [...], fieldNames: [...] }
},
table: { title: "...", messages: [...] }
}
Assuming you had a list of errors from the server, you might do something like this:
var errors = { rows: {}, table: {} }
errorsFromServer.forEach(
error => errors.rows[error.Id] = { title: "...", messages: [...], fieldNames: [...] }
);
errors.table.title = "We found "+errorsFromServer.length+" error(s). ...";
errors.table.messages = [...];
cmp.set("v.errors", errors);
Best Answer
As you would expect
onCellChange
actions are fired when a table cell's value changes in an inline edit. There's a good example of using this feature hereSo, here is the setup you do in the component. Note the draftValues are there because that's what
onCellChange
actions return on inline edits.the controller is pretty basic. It just calls the handler method
The helper has a bunch going on: