I'm new here and have asked 2 questions before and did not get any replies .. not sure if my profile is not visible publically. Even if you are NOT able to answer the question I appreciate if you are able to post a reply saying you can see my question. Thanks
My question - I have a datatable that shows some assignments of tasks on Home page it shows tasks assigned across all objects and on the specific record it shows tasks assigned for that record. The issue is I need to show the Name on Home Page so they can click and go to the record (no comments column) and on record page the assignments are shown in a separate tab and here I don't need to show the Name column but need the comments column. It works fine on initial load of home page or record page or if the pages are refreshed but the issue is if the user navigates say from record1 and then goes to record2 (no refresh) then an additional column is removed and everytime the user navigates between records a column is removed. Using console.log I can see that connectedCallback method is executed between navigation but the strange thing is the this.initialize = false everytime a new record is navigated to but the this.datatableColumns has one less column that was spliced for the previous record. I am NOT an expert and would like to understand what is going and the sequence of execution like when exactly the Const Columns before export default class definition is executed and the variables of class and then ConnectedCallback() .. Please advice.
<template if:true={isRecordPage}> // seen on RecordPage
<lightning-datatable
data={data}
columns={columnsDataTable}
key-field="Id"
is-loading={loading}
</lightning-datatable>
</template>
<template if:false={isRecordPage}> //seen on Home Page
<lightning-datatable
data={data}
columns={columnsDataTable}
key-field="Id"
is-loading={loading}
</lightning-datatable>
</template>
const columns = [
{
label: "Name", fieldName: "obj", type: "url",
typeAttributes: {
label: {fieldName: "objName"},
target: "_blank",
},
},
{ label: "Date", fieldName: "FieldDate", Type: 'date',
tyepAttributes: {
day: 'numeric', month: 'short', year: 'numeric'
},
},
{ label: "Status", fieldName: "Status", type: "text" },
{ label: "Assigned", fieldName: "Assigned" , type: "text"},
{ label: "Alternate", fieldName: "Alternate", type: "text"},
{ label: "Comments", fieldName: "Comments", type: "text"}
];
export default class GetAssigned extends LightningElement {
initialize = false;
@track data = [];
loading = false;
@track datatableColumns = columns;
@api recordId;
connectedCallback() {
if(!this.initialize) {
this.showButton = true;
if(this.recordId == null) {
this.isRecordPage = false;
this.datatableColumns.splice(5,1); // on HomePage datatable does NOT show Comments)
}
if(!(this.recordId == null)) {
this.isRecordPage = true;
this.datatableColumns.splice(0,1); // on RecordPage (Assignment Tab next to Details) datatable does NOT show Name field
}
this.getAssignment();
this.initialize = true;
}
}
```