You're probably missing out type
attribute in the columns for the formula field. Since it's a formula-text field. The default text column is applied.
You need to add a type attribute
to the columns for that field that should be like,
columns = [
// standard text column
{ label: "Text Column", fieldName: "textCol", wrapText: true },
{
label: "Text Column",
fieldName: "richField",
type: "richText",
wrapText: true,
},
{
label: "Rich Text",
fieldName: "richTextCol__c",
type: "richText", //specify a type attribute here
wrapText: true,
},
];
You can see a live demo here.
Once you get columns from apex. You need to change the type attribute before assigning it to the columns attribute.
connectedCallback() {
result.map((col) => {
if (col.fieldName === YOUR_RICH_TEXT_FIELD) {
return (col.type = "richText");
}
});
this.columns = result;
}
Apex Class
public with sharing class ICRM_DynamicRelatedRecordsList_Ctrlr {
@AuraEnabled (Cacheable= true)
public static String getIconName(String objectName) {
String u;
List<Schema.DescribeTabSetResult> tabSetDesc = Schema.describeTabs();
List<Schema.DescribeTabResult> tabDesc = new List<Schema.DescribeTabResult>();
List<Schema.DescribeIconResult> iconDesc = new List<Schema.DescribeIconResult>();
for (Schema.DescribeTabSetResult tsr : tabSetDesc) {
tabDesc.addAll(tsr.getTabs());
}
for (Schema.DescribeTabResult tr : tabDesc) {
if (objectName == tr.getSobjectName()) {
if (tr.isCustom() == true) {
iconDesc.addAll(tr.getIcons());
} else {
u = 'standard:' + objectName.toLowerCase();
}
}
}
for (Schema.DescribeIconResult ir : iconDesc) {
if (ir.getContentType() == 'image/svg+xml') {
u = 'custom:' + ir.getUrl().substringBetween('custom/', '.svg').substringBefore('_');
break;
}
}
return u;
}
@AuraEnabled (Cacheable= true)
public static String getObjectLabel(String sobjectApiName) {
Schema.SObjectType sobjectType = Schema.getGlobalDescribe().get(sobjectApiName);
Schema.DescribeSObjectResult sobjectDescribe = sobjectType.getDescribe();
return sobjectDescribe.getLabelPlural();
}
@AuraEnabled (Cacheable= true)
public static ColumnAndDataWrapper getFieldSet(String sObjectName, String listOfFields, Id recordId, String relationshipField, Integer recordsToDisplay) {
ColumnAndDataWrapper cdw = new ColumnAndDataWrapper();
List<Columns> columns = new List<Columns>();
String fieldsToFetch = '';
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
Schema.SObjectType ctype = gd.get(sObjectName);
Map<String, Schema.SObjectField> fmap = ctype.getDescribe().fields.getMap();
List<String> fieldList = listOfFields.replaceAll(' ','').split(',');
// Generating a list of columns
for (String f : fieldList) {
if (f == 'Name') {
// Uncomment and replace to allow go to record by clicking name
// columns.add(new Columns(fmap.get(f).getDescribe().getLabel(), 'linkName', 'url'));
columns.add(new Columns(fmap.get(f).getDescribe().getLabel(), 'Name', 'text'));
} else {
columns.add(new Columns(fmap.get(f).getDescribe().getLabel(), f, String.valueOf(fmap.get(f).getDescribe().getType()).toLowerCase()));
}
if (fieldsToFetch != '') {
fieldsToFetch += ',';
}
fieldsToFetch += f;
}
// Get the records of requested object
List<SObject> listData;
if (recordsToDisplay == null) {
listData = Database.query('SELECT Id, ' + fieldsToFetch + ' FROM ' + sObjectName + ' WHERE ' + relationshipField + ' = :recordId ');
} else if (recordsToDisplay != null && recordsToDisplay > 0) {
listData = Database.query('SELECT Id, ' + fieldsToFetch + ' FROM ' + sObjectName + ' WHERE ' + relationshipField + ' = :recordId LIMIT ' + recordsToDisplay);
}
cdw.columns = columns;
cdw.listData = listData;
return cdw;
}
public class Columns {
@AuraEnabled public String label;
@AuraEnabled public String fieldName;
@AuraEnabled public String type;
public Columns(String label, String fieldName, String type) {
this.label = label;
this.fieldName = fieldName;
this.type = type;
}
}
public class ColumnAndDataWrapper {
@AuraEnabled public List<Columns> columns;
@AuraEnabled public List<SObject> listData;
}
}
Best Answer
Yes, absolutely. You can create your own custom component with any tags/content you want and render it in a table cell for that column.
Step 1 : create custom component
Step 2 : Create a new component which extends datatable
Step 3 : We can use the component (that extended datatable) where-ever we want
Full details here: How to use custom LWC lightning component in lightning-datatable