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
Will Sun 14Will Sun 14 

lightning datatable for pricebookentries with search function

Hello,
I would like to create a lightning datatable for pricebookentries with search function, so I can achieve as per below:
- when search bar is empty, then show pricebookentries with filtered pricebook (ABC)
- I can search the product name or product code or product category and receive the pricebookentries results within the filtered pricebook (ABC)
Not sure, where to start with, please help
Best Answer chosen by Will Sun 14
VinayVinay (Salesforce Developers) 
Hi,

Review below link which can help you with your implementation.

https://www.forcetree.com/2019/06/lightning-datatable-client-search.html
https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example

Thanks,
Vinay Kumar

All Answers

VinayVinay (Salesforce Developers) 
Hi,

Review below link which can help you with your implementation.

https://www.forcetree.com/2019/06/lightning-datatable-client-search.html
https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example

Thanks,
Vinay Kumar
This was selected as the best answer
Will Sun 14Will Sun 14
Hi Vinay, thanks for your help, do you know how to write a test class code for apex class from forcetree?
public class LightningDataTableController {
	@AuraEnabled
    public static List<sObject> fetchData() {
        //Query and return list of Contacts
        List<SObject> objRecords = [SELECT FirstName, LastName,Email from Contact LIMIT 10];
        return objRecords;
    }
}

and here is the code I have converted
 
public class LightningDataTableController {
    @AuraEnabled
    public static List<PricebookEntry> fetchData() {
        //Query and return list of Contacts
        id userId = UserInfo.getUserId();
        User u = [select id, contactId from User where id = : userId];
        id getContactId = u.contactId;
        List<Contact> cont = new List<Contact>();
        cont = [SELECT AccountId, Title, Name, Email FROM Contact Where Id =: getContactId];
        String dealerId = '';
        if(cont != null && cont.size() > 0){
            dealerId = cont[0].AccountId;
        }
        List<PricebookEntry> objRecords = [SELECT id,Product_Category__c, Product_Name__c,ProductCode,UnitPrice,Inventory_Status__c,Inventory_Description__c from PricebookEntry  where isActive =true AND Pricebook2.isStandard = false AND Pricebook2.Dealer__c =: dealerId LIMIT 900];
        return objRecords;
    }
}

Thank you