function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sainath VenkatSainath Venkat 

LWC Datatable to show records by grouping based on picklist field

I am working on one of the lightning web component which will show child records based on picklist value, On parent detail page, I will have component which will fetch and display the child records but I want to show them based on picklist field, I want to group records and show them based on picklist value, on child object I have picklist field for which I need to group records based on that value
Picklistvalue1
ChildRecord1
ChildRecord2

Picklistvalue2
ChildRecord100
ChildRecord101

Picklistvalue3
ChildRecord200
ChildRecord201
I tried below apex class but just want to know whether I am on right track and also how to create LWC Component
 
public class RightTagWrapper {
@AuraEnabled
public String TagTypeName;
@AuraEnabled
public List<Shadow_Note__c> shadownotes;

public RightTagWrapper(String TagTypeName, List<Shadow_Note__c> shadownotes) {
   this.TagTypeName = TagTypeName;
   this.shadownotes = shadownotes;
}
  @AuraEnabled(Cacheable=true)
  public static List<RightTagWrapper> caseTrxMap(Id RecordId){
string caseRecordId;
        List<Root_Cause_Analysis__c> RCARecord= [select Id,Case__c from Root_Cause_Analysis__c where Id=:RecordId];
        for(Root_Cause_Analysis__c rca: RCARecord){
            caseRecordId = rca.Case__c;
        }

List<RightTagWrapper> shadowNotesTagList = new List<RightTagWrapper>();
Map<string,string> TagPickvals = new Map<string,string>();
             Schema.DescribeFieldResult fieldResult = Shadow_Note__c.Note_Tag__c.getDescribe();
             List<Schema.PicklistEntry> ple =fieldResult.getPicklistValues();
             for (Schema.PicklistEntry a:ple ){
             TagPickvals.put(a.value,a.Label);
             }

List<Shadow_Note__c> allshadownotes = [SELECT Note__c,Note_Tag__c From Shadow_Note__c 
                               WHERE Case__c =: caseRecordId AND Note_Tag__c != null ORDER BY CreatedDate ASC LIMIT 10];
List<Shadow_Note__c> shadownotestagType;
for (string str: TagPickvals.Keyset()) {

    shadownotestagType = new List<Shadow_Note__c>();

    for (Shadow_Note__c sn : allshadownotes) {
        if (TagPickvals.containsKey(sn.Note_Tag__c)) {
              shadownotestagType.add(sn);
        }                 
    }

    shadowNotesTagList.add(
        new RightTagWrapper(
           TagPickvals.get(str),
           shadownotestagType
       )
   );

}
return shadowNotesTagList;
  }
  }

 
AbhishekAbhishek (Salesforce Developers) 
Yes, you are on the right track.


Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.