You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Datatable checkbox to mark tasks as completed
Hello, I would like to change my component datatable code so if the checkbox is checked the status of the task shown is marked as completed? Does somebody know how it can be made? If you like I share my code sample
You can follow the below code for your reference:-
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
COMPONENT
<aura:component controller="TaskController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="tasks" type="Task[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:attribute name="mycolumns" type="List"/>
<lightning:card iconName="standard:task" title="Aufgaben">
<div class="slds-card__body slds-card__body_inner">
<div style="padding-left: 62%; margin-top: -2rem;">
<lightning:button label="Aufgaben Anzeigen" onclick="{! c.openTask}"/>
</div>
</div>
<div style= "font-size: 15px; font-weight: bold; margin-left:15px; margin-top:10px;">
Überfällig
</div>
<div>
</div>
<div>
<aura:if isTrue="{!not(empty(v.tasks))}">
<lightning:datatable data="{!v.tasks }"
columns="{!v.mycolumns }"
keyField="Id"
hideCheckboxColumn="false"
/>
<aura:set attribute="else">
<div Style="text-align : center"> Keine Aufgaben</div>
</aura:set>
</aura:if>
</div>
</lightning:card>
</aura:component>
Javascript
({
doInit: function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Thema', fieldName: 'SubjectName', type: 'url',
typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
{label: 'Status', fieldName: 'Status', type: 'picklist', fixedWidth: 160 },
]);
var action = component.get("c.loadTasks");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
var records =response.getReturnValue();
records.forEach(function(record){
record.SubjectName = '/'+record.Id;
record.ActivityDate= record.ActivityDate;
});
component.set("v.tasks", records);
}
});
$A.enqueueAction(action);
},
openTask: function(component, event, helper) {
window.open('');
},
})
APEX
public with sharing class TaskController {
//ÜBERFÄLLIG - Abfrage Tasks, wo das Activity Date abgelaufen und der Status "Not Completed" ist//
@AuraEnabled
public static List<Task> loadTasks(List<Id> recordId){
string userId = UserInfo.getUserId();
return[SELECT Subject, ActivityDate, Status FROM Task WHERE ActivityDate< TODAY AND OwnerId=:userId AND Status !='Completed'];
}
}
coffee printer (https://en.coffeecolorato.com/)