You need to sign in to do that
Don't have an account?
Ramakrishna K
How to pass two parameters to serverside controller using "onrowaction" lightning datatable
Hi All ,
i'm trying to update a record using "onrowaction " button in lightning datatable , when i'm passing the parameters to server side controller getting this error "Cannot read property 'updaterecord' of undefined".
Please help me to find solutions for below querrys
1. How to capture row id and pass to server side controller .
2. How to get the component value ( getting error 'Cannot read property 'updaterecord' of undefined')
2. Is it possible to call helper method using "onrowaction " . Below my sample code
Controller :
component.set('v.columns', [
{label: $A.get("$Label.c.AccountName"), fieldName: 'Name', type: 'text', sortable : true},
{label: 'Update', type: 'button', initialWidth: 135, typeAttributes: { label: 'Update', name: 'view_details', title: 'Click to View Details'}}]);
handleRowAction :function(component, event, helper){
var action = event.getParam('action');
var row = event.getParam('row');
switch (action.name) {
default:
helper.showRowDetails(row);
break;
}
Helper :
showRowDetails : function(row ,component, event,helper ) {
// var kkk = component.get("v.AccountID");
alert("Showing opportunity " + row.Name + " closing on " + row.Id);
helper.updaterecord(component, event,helper);
},
updaterecord : function(cmp, event,helper ) {
var action = cmp.get("c.updaterecord");
action.setParams({"focID " : cmp.get("v.kkrecordId")});
action.setCallback(this, function(response) {
var state = response.getState();
var responseval = response.getReturnValue();
if (cmp.isValid() && state === "SUCCESS" && responseval.isSuccess) {
console.log(response.getReturnValue());
window.location.replace("/"+cmp.get("v.kkrecordId"));
}
else if(state == "ERROR" || !responseval.isSuccess){
alert(responseval.message);
}
});
Component :
<lightning:datatable data="{! v.allacountlist}" class="slds-m-top_medium"
columns="{! v.columns }"
keyField="id"
aura:id="tableid"
hideCheckboxColumn="true"
onrowaction="{! c.handleRowAction }"/>
i'm trying to update a record using "onrowaction " button in lightning datatable , when i'm passing the parameters to server side controller getting this error "Cannot read property 'updaterecord' of undefined".
Please help me to find solutions for below querrys
1. How to capture row id and pass to server side controller .
2. How to get the component value ( getting error 'Cannot read property 'updaterecord' of undefined')
2. Is it possible to call helper method using "onrowaction " . Below my sample code
Controller :
component.set('v.columns', [
{label: $A.get("$Label.c.AccountName"), fieldName: 'Name', type: 'text', sortable : true},
{label: 'Update', type: 'button', initialWidth: 135, typeAttributes: { label: 'Update', name: 'view_details', title: 'Click to View Details'}}]);
handleRowAction :function(component, event, helper){
var action = event.getParam('action');
var row = event.getParam('row');
switch (action.name) {
default:
helper.showRowDetails(row);
break;
}
Helper :
showRowDetails : function(row ,component, event,helper ) {
// var kkk = component.get("v.AccountID");
alert("Showing opportunity " + row.Name + " closing on " + row.Id);
helper.updaterecord(component, event,helper);
},
updaterecord : function(cmp, event,helper ) {
var action = cmp.get("c.updaterecord");
action.setParams({"focID " : cmp.get("v.kkrecordId")});
action.setCallback(this, function(response) {
var state = response.getState();
var responseval = response.getReturnValue();
if (cmp.isValid() && state === "SUCCESS" && responseval.isSuccess) {
console.log(response.getReturnValue());
window.location.replace("/"+cmp.get("v.kkrecordId"));
}
else if(state == "ERROR" || !responseval.isSuccess){
alert(responseval.message);
}
});
Component :
<lightning:datatable data="{! v.allacountlist}" class="slds-m-top_medium"
columns="{! v.columns }"
keyField="id"
aura:id="tableid"
hideCheckboxColumn="true"
onrowaction="{! c.handleRowAction }"/>
Here problem is i want capture row.Id and pass to controller , when i set the value to attribute getting Cannot read property error message .
component.set("v.accid" , row.id);
class :
public static Account updaterecord(ID CusId , ID Accid) {
Account objacc = [select id,Sold_to_customer__c from Account where id=:CusId ];
objacc.Sold_to_customer__c = Accid ;
try{
update objacc;
}
catch(exception e){}
return objacc ;
}
updaterecord : function(row ,cmp, event,helper ) {
var action = cmp.get("c.updaterecord");
action.setParams({"CusId " : cmp.get("v.kkrecordId") ,"Accid" : 'here i want to pass row id'});
action.setCallback(this, function(response) {
var state = response.getState();
var responseval = response.getReturnValue();
if (cmp.isValid() && state === "SUCCESS" && responseval.isSuccess) {
console.log(response.getReturnValue());
window.location.replace("/"+cmp.get("v.kkrecordId"));
}
else if(state == "ERROR" || !responseval.isSuccess){
alert(responseval.message);
}
});
component.set('v.columns', [
{label: $A.get("$Label.c.AccountName"), fieldName: 'Name', type: 'text', sortable : true},
{label: 'Update', type: 'button', initialWidth: 135, typeAttributes: { label: 'Update', name: 'view_details', title: 'Click to View Details'}}]);
handleRowAction :function(component, event, helper){
var action = event.getParam('action');
var row = event.getParam('row');
switch (action.name) {
default:
helper.updaterecord (row,component, event, helper);
break;
}
<lightning:datatable data="{! v.allacountlist}" class="slds-m-top_medium"
columns="{! v.columns }"
keyField="id"
aura:id="tableid"
hideCheckboxColumn="true"
onrowaction="{! c.handleRowAction }"/>
tried multiple ways but getting below errors
Cannot read property 'get' of undefined
Cannot read property 'indexOf' of undefined
from
TO
Cannot read property 'get' of undefined
Try using different names for the controller method in javascript and your apex method name (both are named as updaterecord.
"Use unique names for client-side and server-side actions in a component. A JavaScript function (client-side action) with the same name as an Apex method (server-side action ) can lead to hard-to-debug issues. (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm)"
and if that does not help at the point you are accessing var row = event.getParam('row'); if you console out row.Id do you have the value? before you set it for the server side param?
Thanks,
Ashwin
Hi,
According to: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_helper.htm
since that you should fix helper method call in helper ( helpers usually do not have parameter helper so remove : " ,helper" ) , and rest change commented in code below.
Not sure if ithat helps to solve the issue, but at least that's what should be changed first.Enjoy IT ;)