You need to sign in to do that
Don't have an account?
Gautam_Kasukhela
How to show Record Type's Name using lightning:dataTable
I am building a custom component to show a list of Cases filtered by a certain criteria. I am using <lightning:dataTable> for this. One of the columns in the list is Record Type and I am unable to display the Name of the Record Type in my list component. It shows up as Id.
In the helper, on the column attributes for Record Type fieldName, I have tried options other than 'RecordTypeId' but that do not show anything in the column. When I run the query in the Console I can see the developer name. What am I missing or doing incorrectly here.
<lightning:datatable data="{! v.caseData}" columns="{! v.caseColumns}" keyField="Id" hideCheckboxColumn="true"/> //Helper. JS component.set('v.caseColumns', [ {label: 'Case Number', fieldName: 'linkName', type: 'url', typeAttributes: {label: { fieldName: 'CaseNumber'},target: '_blank'}}, {label: 'Status', fieldName: 'Status', type: 'text'}, {label: 'Subject', fieldName: 'Subject', type: 'text'}, {label: 'Record Type', fieldName: 'RecordTypeId', type: 'text'}, ]); //Controller code listOfCases = [SELECT Id, CaseNumber, Status, RecordType.Name, Subject, OwnerId, CreatedDate FROM Case WHERE xyz...];
In the helper, on the column attributes for Record Type fieldName, I have tried options other than 'RecordTypeId' but that do not show anything in the column. When I run the query in the Console I can see the developer name. What am I missing or doing incorrectly here.
You can use the below approaches for this.
1. Using the Wrapper Class in Apex controller instead of normal Sobject List return: ( Simple Approach)
https://developer.salesforce.com/forums/?id=9060G0000005V95QAE
2. Using Flatten function in Client side controller:
In the below link they are fetching the Owner Name in table simlarly you have to use Record Type Name.
https://iwritecrappycode.wordpress.com/2017/11/22/salesforce-lightning-datatable-query-flattener/
https://www.wissel.net/blog/2018/08/lightning-datatables-and-relationship-queries.html
https://salesforce.stackexchange.com/questions/200761/parent-field-in-lightning-datatable/200779
Thanks,
Maharajan.C
All Answers
You can use the below approaches for this.
1. Using the Wrapper Class in Apex controller instead of normal Sobject List return: ( Simple Approach)
https://developer.salesforce.com/forums/?id=9060G0000005V95QAE
2. Using Flatten function in Client side controller:
In the below link they are fetching the Owner Name in table simlarly you have to use Record Type Name.
https://iwritecrappycode.wordpress.com/2017/11/22/salesforce-lightning-datatable-query-flattener/
https://www.wissel.net/blog/2018/08/lightning-datatables-and-relationship-queries.html
https://salesforce.stackexchange.com/questions/200761/parent-field-in-lightning-datatable/200779
Thanks,
Maharajan.C