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
sfdc developer 1056sfdc developer 1056 

How to display the selected rows of data table in the UI even after clicking on the search button

Hi Team,
I have an requirement to display the records of Account based on the search criteria in data Table in LWC.
What I want is if I select any row and again search for other accounts then in the UI intially my first selected account record should come and then records based on the search criteria should come.

Can anyone help me on this?
 
PriyaPriya (Salesforce Developers) 
Hi,
 

Please try this below approach:-

1. create a list in lwc to display values in datatable(first variable). Use this variable for data attribut in data table.
2. create another variable to hold the search results based on keyword from apex(second variable)
3. assign this second variable value to first variable and display the search result
4. if you select any record from this list, use onrowselection attribute in datatable to call a method which can store the selected records in temporary variable(third variable)
5. now when user inputs and search again, your search results are stored in second variable
6. and before assigning second variable to first variable, also push the values of both third and second variable to first variable

If the above information helps you, please mark it as best answer.
Regards,

Priya Ranjan