You need to sign in to do that
Don't have an account?
sumit d
lightning component to remove records from list not delete
Hi All,
i have requirement in which i want to show custom object(FBG_Family__c) records in lighning component.every record has checkbox besides it and when the checkbox is clicked that record should be removed from the list (not delete from database)component.
how to do it?
Any suggestions?
i have requirement in which i want to show custom object(FBG_Family__c) records in lighning component.every record has checkbox besides it and when the checkbox is clicked that record should be removed from the list (not delete from database)component.
how to do it?
Any suggestions?
Regards,
Khan Anas
All Answers
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement (I have used Transport custom object, you can change it to FBG Family).
Apex:
Component:
Controller:
CSS:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
i have Name as auto number and two lookup field. what should i use in type in controller?
i tried as below:-
doinit : function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Name', fieldName: 'Name', type: 'Auto Number'},
{label: 'Sister Company', fieldName: 'Sister_Company__c', type: 'id'},
{label: 'Sister Company', fieldName: 'Sister_Company2__c', type: 'id'}
]);
but its not showing anything.Any suggestions?
For lookup fields, you have to flatten the data (server side or client side). It's a valid use case to consider.
Then replace "Account.Name" with "AccountName" in the column data.
And for auto numbers, you can use a number as a type. Below is the sample code:
Component:
Controller:
Apex:
I hope it helps you.
Regards,
Khan Anas
i have implemented what you suggested ,but its not working.
am i missing anything?
my controller is given below:-
({
doinit : function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Name', fieldName: 'Name', type: 'integer'},
{label: 'Sister Company', fieldName: 'Sister_Company__c', type: 'text'},
{label: 'Sister Company', fieldName: 'Sister_Company2__c', type: 'text'}
]);
var action = component.get('c.fetchRecords');
action.setCallback(this, function(response){
var state = response.getState();
if(state === "SUCCESS"){
var allValues = response.getReturnValue();
for (var i = 0; i < allValues.length; i++) {
var row = allValues[i];
if (row.Account) row.Sister_Company__c = row.Account.Name;
}
console.log("allValues--->>> " + allValues);
component.set('v.mydata', allValues);
}
else if(state === "ERROR") {
var errors = response.getError();
if(errors){
if(errors[0] && errors[0].message){
console.log("Error Message: " + errors[0].message);
}
}
else{
console.log("Unknown Error");
}
}
});
$A.enqueueAction(action);
},
removeRow : function(component, event, helper){
var selRows = event.getParam('selectedRows');
// Remove the record from the table
var rows = component.get('v.mydata');
for (var i = 0; i<selRows.length; i++){
var rowIndex = rows.indexOf(selRows[i]);
console.log('rowIndex---->>> ' + rowIndex);
var r=rows.splice(rowIndex, 1);
console.log('rrr---->>> ' + JSON.stringify(r));
component.set('v.mydata', rows);
}
}
})
Regards,
Khan Anas
when i tried as you said its not showing anything in Sister_Company__c
here my object is FBG_Family__c and Sister_Company__c ,Sister_Company2__c are field on FBG_Family__c which are lookup of Account.
i tried like this :-
var allValues = response.getReturnValue();
for (var i = 0; i < allValues.length; i++) {
var row = allValues[i];
if (row.FBG_Family__c) row.Sister_Company__c = row.Sister_Company__c.Name;
}
console.log("allValues--->>> " + allValues);
component.set('v.mydata', allValues);
is it right?
thanks for the help.
found the solution:-
var allValues = response.getReturnValue();
for (var i = 0; i < allValues.length; i++) {
var row = allValues[i];
row.s1 = row.Sister_Company__r.Name;
}
for (var i = 0; i < allValues.length; i++) {
var row = allValues[i];
row.s2 = row.Sister_Company2__r.Name;
}