I need to hide the View button inside Lightning Datatable based on Team Group Name in that same row
If team Group name is blank then view button must be hidden and if team group name is not blank then i need to show view button
Here is my code:
columns: [
{label: "Course Title", fieldName: "CourseTitle", type: "text"},
{label: "Team Group Name", fieldName: "TeamGroupName", type: "text"},
{label: "Campus Name", fieldName: "CampusName", type: "text"},
{label: "Course", fieldName: "Course", type: "text"},
{label: "Section ID", fieldName: "SectionID", type: "text"},
{label: "Session", fieldName: "Session", type: "text"},
{label: "Course Level", fieldName: "CourseLevel", type: "text"},
{label: "Term Length", fieldName: "TermLength", type: "text"},
{type: "button", typeAttributes: {
label: 'View',
name: 'View',
title: 'View',
disabled: false,
value: 'view',
iconPosition: 'left'
}}
]
Component:
<aura:component implements="force:appHostable"
controller="Teams_Controller">
<aura:attribute type="Account[]" name="acctList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>
<lightning:datatable data="{! v.acctList }"
columns="{! v.mycolumns }"
keyField="id"
hideCheckboxColumn="false"
onrowaction="{!c.viewRecord}"/>
I've had the same issue as yours.
I managed to solve it by following the solution here.
Edit: I'm posting also here the solution. It should be similar to your case.
Component:
<aura:component implements="force:appHostable"
controller="AccountListController">
<aura:attribute type="AccountWrapper[]" name="acctList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>
<lightning:datatable data="{! v.acctList }"
columns="{! v.mycolumns }"
keyField="id"
hideCheckboxColumn="true"
onrowaction="{!c.viewRecord}"/>
Component Controller:
({
fetchAccounts : function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Account Name', fieldName: 'accName', type: 'text'},
{label: 'Industry', fieldName: 'accIndustry', type: 'text'},
{label: 'Type', fieldName: 'accType', type: 'text'},
{label: 'Active?', fieldName: 'accActive', type: 'text'},
{type: "button", typeAttributes: {
label: 'View',
name: 'View',
title: 'View',
disabled: { fieldName: 'isActive'},
value: 'view',
iconPosition: 'left'
}}
]);
var action = component.get("c.fetchAccts");
action.setParams({
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.acctList", response.getReturnValue());
}
});
$A.enqueueAction(action);
},
viewRecord : function(component, event, helper) {
var recId = event.getParam('row').accId;
var actionName = event.getParam('action').name;
if ( actionName == 'View') {
var viewRecordEvent = $A.get("e.force:navigateToURL");
viewRecordEvent.setParams({
"url": "/" + recId
});
viewRecordEvent.fire();
}
}
})
Apex Classes:
public class AccountWrapper {
#AuraEnabled
public String accName;
#AuraEnabled
public Boolean isActive;
#AuraEnabled
public String accIndustry;
#AuraEnabled
public String accType;
#AuraEnabled
public String accActive;
#AuraEnabled
public String accId;
}
AccountListController:
public class AccountListController {
#AuraEnabled
public static List < AccountWrapper > fetchAccts() {
List < AccountWrapper > listAcctWrapper = new List < AccountWrapper >();
for ( Account acc : [ SELECT Id, Name, Industry, Type, Active__c FROM Account LIMIT 10 ] ) {
AccountWrapper AccountWrap = new AccountWrapper();
AccountWrap.accName = acc.Name;
AccountWrap.isActive = acc.Active__c == 'Yes' ? true : false;
AccountWrap.accIndustry = acc.Industry;
AccountWrap.accType = acc.Type;
AccountWrap.accActive = acc.Active__c;
AccountWrap.accId = acc.Id;
listAcctWrapper.add(AccountWrap);
}
return listAcctWrapper;
}
}
Hope it helps you.
Related
I have such an object
the "from" field and the "to" field are responsible for the date (shows the value for the selected date period).
the currency field shows the default currency from which other currencies are converted.
field enter currency - (my test field which is not needed yet).
field value is the value of my currency.
my currencies are stored in Manage Currencies
I want to use as many currencies as possible
but I don't know how to do it right because if I continue to add currencies through Manage Currencies, I will have to correct the code as well, because my table filling looks like this:
<template if:true={data}>
<lightning-datatable
key-field="id"
hide-checkbox-column
data={data}
columns={columns}>
</lightning-datatable>
</template>
____________________________________________________________
#track columns = [
{ label: 'Date', fieldName: 'key'},
{ label: 'USD', fieldName: 'USD', type: 'currency' },
{ label: 'CAD', fieldName: 'CAD', type: 'currency' },
{ label: 'EUR', fieldName: 'EUR', type: 'currency' },
{ label: 'GBP', fieldName: 'GBP', type: 'currency' },
{ label: 'KZT', fieldName: 'KZT', type: 'currency' },
{ label: 'BYN', fieldName: 'BYN', type: 'currency' },
];
getExchangeRates({baseCurrency : this.defaultCurrency, dateFrom : this.dateFrom, dateTo : this.dateTo, value : this.defaultValueSelectedCurrency})
.then(resultJSON => {
let result = JSON.parse(resultJSON);
let recordsByDates = result.rates;
console.log('Test result 2');
console.log(recordsByDates);
this.data = [];
for (var key in recordsByDates) {
let record = {
key: key,
date : recordsByDates[key].date,
USD : recordsByDates[key].USD,
CAD : recordsByDates[key].CAD,
EUR : recordsByDates[key].EUR,
GBP : recordsByDates[key].GBP,
BYN : recordsByDates[key].BYN,
KZT : recordsByDates[key].KZT
}
this.data.push(record);
}
console.log(record);
console.log(this.data);
})
.catch(error => {
this.error = error;
console.log(error);
});
and it will look terrible:
below is my code:
const data = [];
Object.keys(json).forEach(key => {
const jobStr = json[key];
console.log(`=== historicalJobCallback jobStr: ${jobStr}`);
const jobItem = jobStr.split(',');
data.push({
jobId: <a href={Utils.getLungoEndpoint() + jobItem[0]} target="_blank" rel="noopener noreferrer"
className={classes.link}>{jobItem[0]}</a>,
jobName: jobItem[1],
submittedBy: jobItem[2],
submittedTime: jobItem[3],
tenant: jobItem[4],
business: jobItem[5]
})
});
setState({
columns: [
{
title: 'Job ID',
field: 'jobId',
render: rowData => <a href={Utils.getLungoEndpoint() + jobItem[0]} target="_blank"
className={classes.link}>{jobItem[0]}</a>
},
{title: 'Job Name', field: 'jobName'},
{title: 'Submitted By', field: 'submittedBy'},
{title: 'Submitted Time', field: 'submittedTime'},
{title: 'Tenant', field: 'tenant'},
{title: 'Business', field: 'business'},
],
data: data
});
As you can see the jobId column is a link, the search feature works for other columns except the job id column, I suspect it is due to the job id text is wrapped in a link, how can I make it searchable?
thanks for the suggestion by #Yatrix, made my code like below and the search is now working for link:
Object.keys(json).forEach(key => {
const jobItem = json[key].split(',');
data.push({
jobId: {
name: jobItem[0],
url: Utils.getLungoEndpoint() + jobItem[0]
},
jobName: jobItem[1],
submittedBy: jobItem[2],
submittedTime: jobItem[3],
tenant: jobItem[4],
business: jobItem[5]
})
});
console.log(`=== historicalJobCallback data: ${JSON.stringify(data)}`);
setState({
columns: [
{
title: 'Job ID',
field: 'jobId',
customFilterAndSearch: (term, rowData) => (rowData.jobId.name).indexOf(term) != -1,
render: rowData => <Link href={rowData.jobId.url} target='_blank'
color='secondary'>{rowData.jobId.name}</Link>
},
{title: 'Job Name', field: 'jobName'},
{title: 'Submitted By', field: 'submittedBy'},
{title: 'Submitted Time', field: 'submittedTime'},
{title: 'Tenant', field: 'tenant'},
{title: 'Business', field: 'business'},
],
data: data
});
I have an nested object array like this.
here is my array:
public collections: ICollections[] = [
{
collectionName: 'Brands',
collectionFields: [
{
columnTitle : 'brandTitle',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.input,
controlType: controlsEnum.input,
controlProperties:
{
placeholder: 'Enter brand title here ...',
type: 'text',
autocomplete: false,
}
},
columnWidth: 200
}
],
collectionFieldValidation: [{name: 'test'}],
hasPaginator: true,
stickyColumn: 0,
stickyHeader: true
},
{
columnTitle : 'brandURL',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.input,
controlType: controlsEnum.input,
controlProperties: {
placeHolder: 'Enter Brand URL',
type: 'text',
autocomplete: false,
}
},
columnWidth: 300
},
{
columnTitle : 'brandDescription',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.textarea,
controlType: controlsEnum.textarea,
controlProperties: {
placeHolder: 'Enter Brand Description',
type: 'text',
autocomplete: false,
}
},
columnWidth: 300
}
];
I want to reach to placeholder field. how do I find it by having only collectionName field with Brands value and columnTitle field with brandURL value ?
this question asked before just with collectionName field value but I find out that my filter should include more than one field.
first of all, find the collection that corresponds to "Brands" or any other thing:
let result = collections.find(p => p.collectionName === "Brands");
then get the placeholder field:
change your_index to 0 or your specific index
if (result) {
let placeholder = result.collectionFields[your_index].control.controlProperties.placeholder;
}
Here is my solution :
placeholder_finder(collectionSearchKey: string, fieldSearchKey: string): string {
let field: any;
let placeholder: string;
const obj = this.genInfo.collections.filter(
x => x.collectionName === collectionSearchKey
);
obj.forEach(data => {
field = data.collectionFields.filter(
x => x.columnTitle === fieldSearchKey
);
});
field.forEach(element => {
placeholder = element.control.controlProperties.placeHolder;
});
return placeholder;
}
Nested property keys is working fine with default type. But it's not working with the below custom template. Why ?
Here is my fields:
vm.fields = [
{
type: 'editableInput',
key: 'profile.name.firstname',
templateOptions: {
label: 'First Name'
}
},
{
type: 'editableInput',
key: 'profile.name.lastname',
templateOptions: {
label: 'Last Name'
}
}
];
What I expected :
{
"profile": {
"name": {
"firstname": "rajagopal",
"lastname": "subramanian"
}
}
But this is what I get:
{
"profile.name.firstname": "rajagopal",
"profile.name.lastname": "subramanian"
}
My Formly Config:
formlyConfig.setType({
extends: 'input',
template: '<div><span editable-text="model[options.key]" e-name="{{::id}}"}}">{{ model[options.key] || "empty" }}</span></div>',
name: 'editableInput'
});
Here is JSBIN
Thanks in advance.
The issue is with how nested keys work with angular-formly. Basically it only works with elements that have an ng-model. The work around for you is to use the model property, and not nested keys (like this):
{
type: 'editableInput',
model: 'model.profile.name',
key: 'firstname',
templateOptions: {
label: 'First Name',
placeholder: 'Enter your First Name'
}
},
{
type: 'editableInput',
model: 'model.profile.name',
key: 'lastname',
templateOptions: {
label: 'Last Name',
placeholder: 'Enter your First Name'
}
}
Good luck!
profile.name.firstname - > profile[name][firstname]
It's my imagine.I have never used Angular
I am trying to save data to local storage and I want to use my own ID.
But new id is generated.. and not using my ID.
My model:
Ext.define('mOQOLD.model.ActivityList',{
extend:'Ext.data.Model',
config:{
dProperty : 'uniqueid', // dummy name(not a field)
clientIdProperty : 'ID',
identifier: {
type: 'simple'
},
fields: [
{ name: "ID", type: "auto" },
{ name: "activityID", type: "int" },
{ name: "newRandom", type: "float" },
{ name: "rTime", type: "date", dateFormat: "Y-m-d H:i:s" }
]
}
});
My store:
Ext.define('mOQOLD.store.ActivityListStoreOffline',{
extend:'Ext.data.Store',
requires:["mOQOLD.model.ActivityList",
'Ext.data.proxy.LocalStorage'],
config:{
storeId:"ActivityListStoreOffline",
model:"mOQOLD.model.ActivityList",
grouper: {
groupFn: function(rec) {
var date = rec.get("actDtlStime");
return Ext.Date.format(date, "h a");
}
},
autoLoad:false,
sorters: [
{ property: "actDtlStime", direction: "ASC" }
],
proxy : {
type : 'localstorage',
id : "ActivityListStoreOffline",
model : "mOQOLD.model.ActivityList",
reader: {
type: "json"
}
}
}
})
The result( chrome) :
key : ActivityListStoreOffline-ext-record-19
value:
{"ID":"153",15:13:00","activityID":111,"newRandom":null,"rTime":"2015-05-26 19:31:51","id":"ext-record-19"}
What I expect:
key : ActivityListStoreOffline-153
value:
{"ID":"153",15:13:00","activityID":111,"newRandom":null,"rTime":"2015-05-26 19:31:51"} no id generated!!!
Thanks in advance..
There are two places you can set the ID:
In the model(http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Model-cfg-idProperty)
and in the reader (http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.reader.Reader-cfg-idProperty)
Both places use the "idProperty" attribute. Which defaults to lowercase 'id'.
For example, change your reader to:
proxy : {
type : 'localstorage',
id : "ActivityListStoreOffline",
model : "mOQOLD.model.ActivityList",
reader: {
type: "json",
idProperty: "ID",
}
}