You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
LWC to render child records in datatable
Hello,
I am trying to do the following. Have a button on teh parenet record that will render the child records in a datatable(editable)
What ever is selected I need to be able to create a new record from the rows slected.
I have a LWC and controller. The LWC is wrapped in a aura compone tbut when selected it just has the header columns.
Should I try to grab the child records in the .js?
Then how do I add a button to the LWS to create a new record from the rows slected?
Thank you for your help,
P
I am trying to do the following. Have a button on teh parenet record that will render the child records in a datatable(editable)
What ever is selected I need to be able to create a new record from the rows slected.
I have a LWC and controller. The LWC is wrapped in a aura compone tbut when selected it just has the header columns.
Should I try to grab the child records in the .js?
Then how do I add a button to the LWS to create a new record from the rows slected?
Thank you for your help,
P
1. add onrowselection to let datatable
<lightning-datatable
onrowselection={getRowSelected}>
……
2. Add menu button to column definition
const columns = [ // Other column data here { type: 'action', typeAttributes: { rowActions: actions, menuAlignment: 'left' } } ];
getRowActions(row, doneCallback) {
const actions = [];
actions.push({ 'label': 'Creat a record', 'name': 'create' });
} // simulate a trip to the server
setTimeout(() => { doneCallback(actions); }), 200);
}
3. In J's file
action;
selectedrow;
getRowSelected(event){
this.action = event.detail.action.name;
this.selectedrow = event.detail.row;
// Your code creating a new record
}
All Answers
mycfavisit (https://customersatisfactionsurvey3.home.blog/2020/03/05/mycfavisit/)
1. add onrowselection to let datatable
<lightning-datatable
onrowselection={getRowSelected}>
……
2. Add menu button to column definition
const columns = [ // Other column data here { type: 'action', typeAttributes: { rowActions: actions, menuAlignment: 'left' } } ];
getRowActions(row, doneCallback) {
const actions = [];
actions.push({ 'label': 'Creat a record', 'name': 'create' });
} // simulate a trip to the server
setTimeout(() => { doneCallback(actions); }), 200);
}
3. In J's file
action;
selectedrow;
getRowSelected(event){
this.action = event.detail.action.name;
this.selectedrow = event.detail.row;
// Your code creating a new record
}
Thanks for the reply. So you are not using a controller? How are you selecting the child records and rendering them in the datatable? Thanks,
P
it us very similar to data table in aura component.
https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentation
Read more: QuickBooks Support Phone Number
QuickBooks Support Phone Number
QuickBooks Support Phone Number
I did see that documentation but the table never populated. I just see the header columns.
Thanks,
P
<template>
<lightning-datatable data={contacts} //contact is a variable defined in js file
columns={columns} >
</lightning-datatable> </template>
2. js file
import getContactListfrom '@salesforce/apex/myController.getContactList';
@track contacts;
@wire (getContactList)
wiredContatcts(result) {
if (result.data) {
this.contacts = result.data;
this.error = undefined;
} else if (result.error) {
this.error = result.error.body.message;
this.data = undefined;
}
}
3. apex file
@aurable......
public method List<Contact> getContactList()
{
......
}
Now I do not even see the header columns. I am wondering if its becuase the controller is not returning any data.
So for this example. I would have the LWC in an Action item on athe Account Page. Would that return any data?
Thank you,
P
I don't know why you nest get contact list in another method. I assume it is typo
What do you mean by 'datatable columns have the right setting'?