You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Close tasks with checkbox in List view
Hello, I made a datatable for the task title and status. I want to use the checkbox on the datatable to mark the tasks as completed.
To this day nobody could help me with this issue. Could somebody offer me a help with it?
To this day nobody could help me with this issue. Could somebody offer me a help with it?
Are you using lightning component, then
First you need to fetch from Apex class and update check box accordingly
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
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:attribute name="tasks2" type="Task[]"/>
<aura:attribute name="tasks3" type="Task[]"/>
<aura:attribute name="tasks4" type="Task[]"/>
<aura:attribute name="tasks5" 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"/>
<aura:attribute name="mycolumns2" type="List"/>
<aura:attribute name="mycolumns3" type="List"/>
<aura:attribute name="mycolumns4" type="List"/>
<aura:attribute name="mycolumns5" type="List"/>
<aura:attribute name="DayDate" type="Integer" />
<aura:attribute name="DayDate2" type="Integer" />
<aura:attribute name="DayDate3" type="Integer" />
<aura:attribute name="DayDate4" type="Integer" />
<aura:attribute name="currentDate" type="string"/>
<aura:attribute name="TomorrowDate" type="string"/>
<aura:attribute name="AfterTomorrowDate" type="string"/>
<aura:attribute name="TwoAfterTomorrowDate" type="string"/>
<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>
<div style= "font-size: 15px; font-weight: bold; margin-left:15px; margin-top:10px;">
{!v.currentDate} - Heute
</div>
<div>
<aura:if isTrue="{!not(empty(v.tasks2))}">
<lightning:datatable data="{!v.tasks2}"
columns="{!v.mycolumns2}"
keyField="Id"
hideCheckboxColumn="false"
onrowselection="{! c.handleRowSelection}" />
<aura:set attribute="else">
<div Style="text-align : center"> Keine Aufgaben </div>
</aura:set>
</aura:if>
</div>
<div style= "font-size: 15px; font-weight: bold; margin-left:15px; margin-top:10px; ">
{!v.TomorrowDate} - {!v.DayDate2}
</div>
<div>
<aura:if isTrue="{!not(empty(v.tasks3))}">
<lightning:datatable data="{!v.tasks3}"
columns="{!v.mycolumns3}"
keyField="Id"
hideCheckboxColumn="false"
onrowselection="{! c.handleRowSelection}" />
<aura:set attribute="else">
<div Style="text-align : center"> Keine Aufgaben</div>
</aura:set>
</aura:if>
</div>
<div style= "font-size: 15px; font-weight: bold; margin-left:15px; margin-top:10px;">
{!v.AfterTomorrowDate} - {!v.DayDate3}
</div>
<div>
<aura:if isTrue="{!not(empty(v.tasks4))}">
<lightning:datatable data="{!v.tasks4}"
columns="{!v.mycolumns4}"
keyField="Id"
hideCheckboxColumn="false"
onrowselection="{! c.handleRowSelection}"/>
<aura:set attribute="else">
<div Style="text-align : center"> Keine Aufgaben</div>
</aura:set>
</aura:if>
</div>
<div style= "font-size: 15px; font-weight: bold; margin-left:15px; margin-top:10px;">
{!v.TwoAfterTomorrowDate} - {!v.DayDate4}
</div>
<div>
<aura:if isTrue="{!not(empty(v.tasks5))}">
<lightning:datatable data="{!v.tasks5}"
columns="{!v.mycolumns5}"
keyField="Id"
hideCheckboxColumn="false"
onrowselection="{! c.handleRowSelection}" />
<aura:set attribute="else">
<div Style="text-align : center"> Keine Aufgaben</div>
</aura:set>
</aura:if>
</div>
</lightning:card>
</aura:component>
CONTROLLER
({
doInit: function(component, event, helper) {
var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sonntag";
weekday[1] = "Montag";
weekday[2] = "Dienstag";
weekday[3] = "Mittwoch";
weekday[4] = "Donnerstag";
weekday[5] = "Freitag";
weekday[6] = "Samstag";
var index = (d.getDay()+1 > 6 ) ? (d.getDay()+1) - 7 : (d.getDay()+1);
var n2 = weekday[index];
component.set('v.DayDate2', n2);
var index2 = (d.getDay()+2 > 6 ) ? (d.getDay()+2) - 7 : (d.getDay()+2);
var n3 = weekday[index2];
component.set('v.DayDate3', n3);
var index3 = (d.getDay()+3 > 6 ) ? (d.getDay()+3) - 7 : (d.getDay()+3);
var n4 = weekday[index3];
component.set('v.DayDate4', n4);
var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(new Date().getDate()+1);
var aftertomorrowdate = new Date();
aftertomorrowdate.setDate(new Date().getDate()+2);
var twoaftertomorrowdate = new Date();
twoaftertomorrowdate.setDate(new Date().getDate()+3);
let options = {"month":"2-digit", "day":"2-digit", "year":"numeric"};
component.set('v.currentDate', today.toLocaleDateString("de-DE",options));
component.set('v.TomorrowDate', tomorrow.toLocaleDateString("de-DE",options));
component.set('v.AfterTomorrowDate', aftertomorrowdate.toLocaleDateString("de-DE",options));
component.set('v.TwoAfterTomorrowDate', twoaftertomorrowdate.toLocaleDateString("de-DE",options));
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);
component.set('v.mycolumns2', [
{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.loadTasks2");
var whatId = component.get("v.recordId");
action.setParams({
"recordId":whatId
});
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.tasks2", records);
}
});
$A.enqueueAction(action);
component.set('v.mycolumns3', [
{label: 'Thema', fieldName: 'SubjectName', type: 'url',
typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
{label: 'Status', fieldName: 'Status', type: 'picklist', initialWidth: 160 },
]);
var action = component.get("c.loadTasks3");
var whatId = component.get("v.recordId");
action.setParams({
"recordId":whatId
});
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.tasks3", records);
}
});
$A.enqueueAction(action);
component.set('v.mycolumns4', [
{label: 'Thema', fieldName: 'SubjectName', type: 'url',
typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
{label: 'Status', fieldName: 'Status', type: 'picklist', initialWidth: 160},
]);
var action = component.get("c.loadTasks4");
var whatId = component.get("v.recordId");
action.setParams({
"recordId":whatId
});
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.tasks4", records);
}
});
$A.enqueueAction(action);
component.set('v.mycolumns5', [
{label: 'Thema', fieldName: 'SubjectName', type: 'url',
typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
{label: 'Status', fieldName: 'Status', type: 'picklist' , initialWidth: 160},
]);
var action = component.get("c.loadTasks5");
var whatId = component.get("v.recordId");
action.setParams({
"recordId":whatId
});
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.tasks5", records);
}
});
$A.enqueueAction(action);
},
openTask: function(component, event, helper) {
window.open('');
},
})
APEX Class
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'];
}
//HEUTE - Abfrage Tasks, wo das Activity Date gleich heute ist//
@AuraEnabled
public static List<Task> loadTasks2(Id recordId){
string userId = UserInfo.getUserId();
return[SELECT Subject, ActivityDate, Status, Abschliessen_del__c FROM Task WHERE ActivityDate = TODAY AND OwnerId=:userId AND Status !='Completed'];
}
//MORGEN - Abfrage Tasks, wo das Activity Date Heute+1 entspricht//
@AuraEnabled
public static List<Task> loadTasks3(Id recordId){
string userId = UserInfo.getUserId();
return[SELECT Subject, ActivityDate, Status, Abschliessen_del__c FROM Task WHERE ActivityDate = TOMORROW AND OwnerId=:userId AND Status !='Completed'];
}
//ÜBERMORGEN - Abfrage Tasks, wo das Activity Date Heute+2 entspricht//
@AuraEnabled
public static List<Task> loadTasks4(Id recordId){
string userId = UserInfo.getUserId();
return[SELECT Subject, ActivityDate, Status, Abschliessen_del__c FROM Task WHERE ActivityDate > TOMORROW AND ActivityDate <= Next_N_Days:2 AND OwnerId=:userId AND Status !='Completed'];
}
//In 3 Tagen - Abfrage Tasks, wo das Activity Date Heute+3 entspricht//
@AuraEnabled
public static List<Task> loadTasks5(Id recordId){
string userId = UserInfo.getUserId();
return[SELECT Subject, ActivityDate, Status, Abschliessen_del__c FROM Task WHERE ActivityDate > Next_N_Days:2 AND ActivityDate <= Next_N_Days:3 AND OwnerId=:userId AND Status !='Completed'];
}
//OHNE DATE - Abfrage Tasks, wo kein Activity Date vorhanden ist//
@AuraEnabled
public static List<Task> loadTasks6(Id recordId){
string userId = UserInfo.getUserId();
return[SELECT Subject, ActivityDate, Status FROM Task WHERE ActivityDate = null AND OwnerId=:userId AND Status !='Completed'];
}
}