How to disable inline Edit for certain profiles.
<lightning:datatable
keyField="Id"
aura:id="subscriberTable"
data="{! v.data }"
columns="{! v.columns }"
hideCheckboxColumn="true"
showRowNumberColumn="false"
initialRows="{! v.recordsToDisplay}" sortedBy="{! v.sortedBy }"
sortedDirection="{! v.sortedDirection }"
onsort="{! c.updateColumnSorting}"
draftValues="{! v.draftValues }"
onsave="{! c.handleSaveEdition }" />
</div>
Js side:
component.set('v.columns', [{
label: 'Name',
fieldName: 'Name',
type: 'text',
sortable: true
},
{
label: 'Alias',
fieldName: 'Alias__c',
type: 'text',
sortable: true
},
{
label: 'Point of Contact(Email)',
fieldName: 'Email__c',
type: 'text',
sortable: true,
editable: true
},
{
label: 'Active',
fieldName: 'Active__c',
type: 'boolean',
sortable: true,
editable: true
},
{
label: 'Portal Access',
fieldName: 'Portal_Access__c',
type: 'boolean',
sortable: true,
editable: true,
},
]);
How to set "Active" field editable to false for these 2 profiles (Test1,Test2).In normal Table we can use aura:if but Iam not sure how to do this here.
//I have tried this approach but it works but a lot of code
JS side:
helper.userEditAccess(component,event,helper);
Helper:
userEditAccess: function(component, event, helper) {
var action = component.get("c.canUserEdit");
action.setCallback(this, function(a) {
var state = a.getState();
if (state === 'SUCCESS') {
if (a.getReturnValue() == true) {
component.set('v.columns', [{
label: 'Name',
fieldName: 'Name',
type: 'text',
sortable: true
},
{
label: 'Alias',
fieldName: 'Alias__c',
type: 'text',
sortable: true
},
{
label: 'Point of Contact(Email)',
fieldName: 'Email__c',
type: 'text',
sortable: true,
editable: true
},
{
label: 'Active',
fieldName: 'Active__c',
type: 'boolean',
sortable: true,
editable: false
},
{
label: 'Portal Access',
fieldName: 'Portal_Access__c',
type: 'boolean',
sortable: true,
editable: false,
},
]);
} else if (a.getReturnValue() == false) {
component.set('v.columns', [{
label: 'Name',
fieldName: 'Name',
type: 'text',
sortable: true
},
{
label: 'Alias',
fieldName: 'Alias__c',
type: 'text',
sortable: true
},
{
label: 'Point of Contact(Email)',
fieldName: 'Email__c',
type: 'text',
sortable: true,
editable: true
},
{
label: 'Active',
fieldName: 'Active__c',
type: 'boolean',
sortable: true,
editable: true
},
{
label: 'Portal Access',
fieldName: 'Portal_Access__c',
type: 'boolean',
sortable: true,
editable: true,
},
]);
}
}
});
// enqueue the action
$A.enqueueAction(action);
}
Apex class:
@AuraEnabled(cacheable=true)
public static Boolean canUserEdit() {
List<string>profileNameList=new List<string>();
List<user>userList=[SELECT ID,PROFILE.NAME,PROFILE.Id FROM USER where profile.name='Test-Admin'];
for(User us:userList){
profileNameList.add(us.PROFILE.Id);
}
Id profileId = UserInfo.getProfileId();
if(profileNameList.contains(profileId)){
return true;
}else{
return false;
}
}