In Lightning, let's see how we can easily access the current record in a list view or data table to update/delete. Those who are familiar with Visualforce will see a slight change in the concept to achieve this as we have a follow a component based design to update/delete record in a list view or data table.
In the below example, we are fetching account records and displaying in a data table with Update, Delete Icon for each record. User could click on any account specific edit, delete to fire the respective action. In this code snippet, we are just showing the trick to access the respective record Id and record object of the user selected account, so that the user could use the selected record id, record object to either edit or delete the record.
Now lets see the parent component(Demo_CRUD_Component) wherein we are fetching accounts and displaying the list of records using an Iteration. In iteration we use a child component(Demo_CRUD_Component_ROW) to display each record. To child component, we are passing single record, so that the edit, delete event can be easily handled in the child component. Let's see the code of parent component(Demo_CRUD_Component), related controller and apex class.
Here is the code of child component wherein we are handling the edit and delete for each record. Since we have designed the child component for each record, it is easy to get the current record or object, selected by user for either edit, delete. Let's see the code of child component(Demo_CRUD_Component_ROW).
Here is the the screenshot associated with the example:
4 comments
Write commentsCan you please share your code
ReplyI tried similar in LWC but all the data is coming in single Data but on placing similar code on parent showing data in correct cells
ReplyEdit button and delete is not working
ReplyEdit button and delete is not working
Replycan you please help for resolve same