You need to sign in to do that
Don't have an account?

Mass delete operation through checkbox in lightning component
Hello everyone,
I need to know how can I perform mass delete operation with the use of checkboxes.
Here is my component.
<pre>
<aura:component implements="force:appHostable" controller="AccountListController">
<aura:attribute name="accounts" type="Account[]"/>
<aura:handler name="init" value="{!this}" action="{!c.getAccount}" />
<ui:button class="slds-button slds-button--destructive" press="{!c.delete}">Delete</ui:button><!--Mass Delete operation-->
<table class="slds-table slds-table--bordered slds-max-medium-table--stacked-horizontal">
<thead>
<tr class="slds-text-heading--label ">
<th class="slds-is-sortable" scope="col">
<ui:inputCheckbox label="" class="check" aura:id="master" click="{!c.checkAll}"/>
Action
</th>
<th class="" scope="col">Account Name</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.accounts}" var="account">
<tr class="slds-hint-parent">
<td class="" data-label="Action" style="padding-left:0;">
<ui:inputCheckbox label="" class="check" text="{!account.Id}" aura:id="dependent"/>
</td>
<td class="" data-label="Account Name" style="padding-left:0;">
<a href="{! '#/sObject/' + account.Id + '/view'}">{!account.Name}</a>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
<aura:component>
</pre>
This is the client side controller:
<pre>
getAccount : function(component,event,helper) {
var action=component.get("c.getAccountList");
action.setCallback(this, function(a) {
component.set("v.accounts", a.getReturnValue());
});
$A.enqueueAction(action);
},
checkAll:function(component,event,helper){
var master= component.find("master");
var dep= component.find("dependent");
var val= master.get("v.value");
if(val==true){
for(var i=0;i<dep.length;i++){
dep[i].set("v.value",true);
}
}else{
for(var i=0;i<dep.length;i++){
dep[i].set("v.value",false);
}
}
},
delete:function(cmp,evt,helper){}
</pre>
This is the sever side controller:
<pre>
public with sharing class AccountListController {
@AuraEnabled
public static List<Account> getAccountList() {
return [SELECT Id,Name,Accountnumber FROM Account order by CreatedDate desc];
}
}
</pre>
Kindly help.
Thanks
Regards
I need to know how can I perform mass delete operation with the use of checkboxes.
Here is my component.
<pre>
<aura:component implements="force:appHostable" controller="AccountListController">
<aura:attribute name="accounts" type="Account[]"/>
<aura:handler name="init" value="{!this}" action="{!c.getAccount}" />
<ui:button class="slds-button slds-button--destructive" press="{!c.delete}">Delete</ui:button><!--Mass Delete operation-->
<table class="slds-table slds-table--bordered slds-max-medium-table--stacked-horizontal">
<thead>
<tr class="slds-text-heading--label ">
<th class="slds-is-sortable" scope="col">
<ui:inputCheckbox label="" class="check" aura:id="master" click="{!c.checkAll}"/>
Action
</th>
<th class="" scope="col">Account Name</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.accounts}" var="account">
<tr class="slds-hint-parent">
<td class="" data-label="Action" style="padding-left:0;">
<ui:inputCheckbox label="" class="check" text="{!account.Id}" aura:id="dependent"/>
</td>
<td class="" data-label="Account Name" style="padding-left:0;">
<a href="{! '#/sObject/' + account.Id + '/view'}">{!account.Name}</a>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
<aura:component>
</pre>
This is the client side controller:
<pre>
getAccount : function(component,event,helper) {
var action=component.get("c.getAccountList");
action.setCallback(this, function(a) {
component.set("v.accounts", a.getReturnValue());
});
$A.enqueueAction(action);
},
checkAll:function(component,event,helper){
var master= component.find("master");
var dep= component.find("dependent");
var val= master.get("v.value");
if(val==true){
for(var i=0;i<dep.length;i++){
dep[i].set("v.value",true);
}
}else{
for(var i=0;i<dep.length;i++){
dep[i].set("v.value",false);
}
}
},
delete:function(cmp,evt,helper){}
</pre>
This is the sever side controller:
<pre>
public with sharing class AccountListController {
@AuraEnabled
public static List<Account> getAccountList() {
return [SELECT Id,Name,Accountnumber FROM Account order by CreatedDate desc];
}
}
</pre>
Kindly help.
Thanks
Regards
update in your code with below code for delete by selected checkbox
in your component add this line for store id of selected checkbox in your js controler in apex class
Read code line by line and Understand this functionality :)
Thanks
let me inform if any problem with it or if it helps you mark it best answer :)
All Answers
update in your code with below code for delete by selected checkbox
in your component add this line for store id of selected checkbox in your js controler in apex class
Read code line by line and Understand this functionality :)
Thanks
let me inform if any problem with it or if it helps you mark it best answer :)
@soni piyush
and what is the staus of your below quetion.
you can ask me any question if any doubt on this question.
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000g2FvIAI
best regards
https://umangsinghal.wordpress.com/2017/06/11/move-selected-table-values-from-one-component-to-another