You need to sign in to do that
Don't have an account?
Filip Poverud 1-9
Lightning Data Table with typeAittributes from Controller
Hi all.
I'm creating a dynamic LE DataTable component using Aura.
I'm producing the Columns in the Controller based upon FieldSets and in the Helper I rewrite Columns in order to cover Related Fields.
I have a small issue with labeling HyperLinks:
Controller Code:
In the Helper I do the rearrangement:
If we look at the actual datasets produced:
So the problem is basically the Labeling of the link.
I have looked at examples and as long as I hardcode the Columns the traditional way with a component.set, everything works. But since this is produced in the controlle and I override it, I'm not sure how to set the proper values in the attribute so it is interpreted correctly.
Thank you in advance
I'm creating a dynamic LE DataTable component using Aura.
I'm producing the Columns in the Controller based upon FieldSets and in the Helper I rewrite Columns in order to cover Related Fields.
I have a small issue with labeling HyperLinks:
Controller Code:
public class DynamicLightningDataTableController { /* Method Name : getObjectRecords Purpose : Create a Lightning Data Table configured by LAB and FieldSets */ @AuraEnabled public static DataTableResponse getObjectRecords(String strObjectName, String strFieldSetName, String strRelativeId, String strRecordId, String strPartnerType){ //Get the fields from the FieldSet Schema.SObjectType SObjectTypeObj = Schema.getGlobalDescribe().get(strObjectName); Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe(); Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(strFieldSetName); //Table Headers List<DataTableColumns> lstDataColumns = new List<DataTableColumns>(); //Fields added to the SOQL query List<String> lstFieldsToQuery = new List<String>(); //The final wrapper response returned to the component DataTableResponse response = new DataTableResponse(); for( Schema.FieldSetMember eachFieldSetMember : fieldSetObj.getFields() ){ String dataType = String.valueOf(eachFieldSetMember.getType()).toLowerCase(); //Mapping Schema Object DataTypes with lightning:datatable component structure if(dataType == 'datetime'){ dataType = 'date'; } //Create a wrapper instance and store Label, fieldName, Type and typeAttributes. DataTableColumns datacolumns = new DataTableColumns( String.valueOf(eachFieldSetMember.getLabel()) , String.valueOf(eachFieldSetMember.getFieldPath()), String.valueOf(eachFieldSetMember.getType()).toLowerCase(), '' ); lstDataColumns.add(datacolumns); lstFieldsToQuery.add(String.valueOf(eachFieldSetMember.getFieldPath())); } //Form an SOQL to fetch the data - Set the wrapper instance and return as response if(! lstDataColumns.isEmpty()){ response.lstDataTableColumns = lstDataColumns; String query = 'SELECT ' + String.join(lstFieldsToQuery, ',') + ' FROM ' + strObjectName + ' WHERE ' + strRelativeId + ' = ' + '\'' + strRecordId + '\' AND ' + strPartnerType + ' !=null'; System.debug(query); response.lstDataTableData = Database.query(query); } return response; } //Wrapper class to hold Columns with Headers public class DataTableColumns { @AuraEnabled public String label {get;set;} @AuraEnabled public String fieldName {get;set;} @AuraEnabled public String type {get;set;} @AuraEnabled public Object typeAttributes {get;set;} //Create and set three variables label, fieldname and type as required by the lightning:datatable public DataTableColumns(String label, String fieldName, String type, String typeAttributes){ this.label = label; this.fieldName = fieldName; this.type = type; this.typeAttributes = typeAttributes; } } //Wrapper class to hold response - This response is used in the lightning:datatable component public class DataTableResponse { @AuraEnabled public List<DataTableColumns> lstDataTableColumns {get;set;} @AuraEnabled public List<sObject> lstDataTableData {get;set;} public DataTableResponse(){ lstDataTableColumns = new List<DataTableColumns>(); lstDataTableData = new List<sObject>(); } } }As you can see I set typeAttributes to blank for now.
In the Helper I do the rearrangement:
// Rename Related Column FieldNames var crows = response.getReturnValue().lstDataTableColumns; for(var i = 0 ; i < crows.length;i++) { var crow = crows[i]; if(crow.fieldName == "Customer__r.Name"){ crow.fieldName = "CustomerName"; }; if(crow.fieldName == "Consultant_View__c"){ crow.type = "url"; crow.typeAttributes = "label: \'linkLabel\'"; console.log("Columns"); console.log(crow); }; } // Rename Related Data Pointers var drows = response.getReturnValue().lstDataTableData; for(var i = 0 ; i < drows.length;i++) { var drow = drows[i]; if(drow.Customer__r){ drow.CustomerName = drow.Customer__r.Name; }; if(drow.Consultant_View__c){ drow.Consultant_View__c = "/lightning/r/PM_Partner__c/a2k0E000000MVkIQAW/view"; drow.linkLabel = "View Detail"; console.log("Data"); console.log(drow); }; }And the returned LE DataTable looks like this:
If we look at the actual datasets produced:
So the problem is basically the Labeling of the link.
I have looked at examples and as long as I hardcode the Columns the traditional way with a component.set, everything works. But since this is produced in the controlle and I override it, I'm not sure how to set the proper values in the attribute so it is interpreted correctly.
Thank you in advance