I have a lightning component that dynamically creates a lightning:datatable when apex returns a list of records. For the most part its working, but im trying to add an onclick event to the row, but however I try it its failing.
$A.createComponent(
"lightning:datatable",
{
"data":component.get("v.results"),
"columns":component.get("v.mycolumns")
//,"onclick": "{!c.onrowselection}"
//,"onrowselection": "{!c.onrowselection}"
},
function(datatable){
if (component.isValid()) {
var targetCmp = component.find('datatable');
var body = targetCmp.get("v.body");
body.push(datatable);
targetCmp.set("v.body", body);
}
}
);
You can see the commented code, if i uncomment it the component will not be created. If you have an idea please post a comment or answer. Thank you.