You need to sign in to do that
Don't have an account?
Rama_SFDC
How to get the table row values in LWC
Hello ,
How to update the records using html table in LWC ? .
I'm facing issue with getting complete row values in lwc in my table one of the column is date field and i need to pass the date field value to js controller as well as to serverside controller
Can someone help me on this , how to update the selected records with input Date field ?
<template>
<template if:true={accounts}>
<table class="slds-table slds-table_cell-buffer slds-table_bordered" id="Table1">
<thead>
<tr class="slds-line-height_reset">
<th class="" scope="col">
<div class="slds-truncate" title="Name">Select</div>
</th>
<th class="" scope="col">
<div class="slds-truncate" title="Phone">Name</div>
</th>
<th class="" scope="col">
<div class="slds-truncate" title="select">Phone</div>
</th>
<th class="" scope="col">
<div class="slds-truncate" title="select">Enquiry Date</div>
</th>
</tr>
</thead>
<tbody>
<template for:each={accounts} for:item="acc">
<tr class="slds-hint-parent" key={acc.Id}>
<th data-label="" scope="row">
<lightning-input type="checkbox" value={acc.Name} data-id={acc.Id}></lightning-input>
</th>
<th data-label="Name" scope="row">
<div class="slds-truncate">{acc.Name}</div>
</th>
<td data-label="Rating">
<div class="slds-truncate">{acc.Phone}</div>
</td>
<td data-label=" Enquiry Date">
<lightning-input type="date" name="input1" ></lightning-input>
</td>
</tr>
</template>
</tbody>
</table>
<lightning-button label="Update Accounts" onclick={updateAccount} style="margin-left: 40%" variant="brand"></lightning-button>
</template>
import { LightningElement, track, wire } from 'lwc';
import getAllAccounts from '@salesforce/apex/AccountTablecontroller.getAllAccounts';
export default class Cssexample extends LightningElement {
@track accounts;
@track errors;
@track selectedAcc;
@track accName ;
@track accId ;
@wire(getAllAccounts)
wireAllAccs({
error,
data
}) {
if (data) {
this.accounts = data;
} else {
this.error = error;
}
}
updateAccount() {
this.selectedAcc = [];
let selectedRows = this.template.querySelectorAll('lightning-input');
for(let i = 0; i < selectedRows.length; i++) {
if(selectedRows[i].checked ) {
this.selectedAcc.push({
Name: selectedRows[i].value,
Id: selectedRows[i].dataset.id
})
}
}
}
}
Thanks
How to update the records using html table in LWC ? .
I'm facing issue with getting complete row values in lwc in my table one of the column is date field and i need to pass the date field value to js controller as well as to serverside controller
Can someone help me on this , how to update the selected records with input Date field ?
<template>
<template if:true={accounts}>
<table class="slds-table slds-table_cell-buffer slds-table_bordered" id="Table1">
<thead>
<tr class="slds-line-height_reset">
<th class="" scope="col">
<div class="slds-truncate" title="Name">Select</div>
</th>
<th class="" scope="col">
<div class="slds-truncate" title="Phone">Name</div>
</th>
<th class="" scope="col">
<div class="slds-truncate" title="select">Phone</div>
</th>
<th class="" scope="col">
<div class="slds-truncate" title="select">Enquiry Date</div>
</th>
</tr>
</thead>
<tbody>
<template for:each={accounts} for:item="acc">
<tr class="slds-hint-parent" key={acc.Id}>
<th data-label="" scope="row">
<lightning-input type="checkbox" value={acc.Name} data-id={acc.Id}></lightning-input>
</th>
<th data-label="Name" scope="row">
<div class="slds-truncate">{acc.Name}</div>
</th>
<td data-label="Rating">
<div class="slds-truncate">{acc.Phone}</div>
</td>
<td data-label=" Enquiry Date">
<lightning-input type="date" name="input1" ></lightning-input>
</td>
</tr>
</template>
</tbody>
</table>
<lightning-button label="Update Accounts" onclick={updateAccount} style="margin-left: 40%" variant="brand"></lightning-button>
</template>
import { LightningElement, track, wire } from 'lwc';
import getAllAccounts from '@salesforce/apex/AccountTablecontroller.getAllAccounts';
export default class Cssexample extends LightningElement {
@track accounts;
@track errors;
@track selectedAcc;
@track accName ;
@track accId ;
@wire(getAllAccounts)
wireAllAccs({
error,
data
}) {
if (data) {
this.accounts = data;
} else {
this.error = error;
}
}
updateAccount() {
this.selectedAcc = [];
let selectedRows = this.template.querySelectorAll('lightning-input');
for(let i = 0; i < selectedRows.length; i++) {
if(selectedRows[i].checked ) {
this.selectedAcc.push({
Name: selectedRows[i].value,
Id: selectedRows[i].dataset.id
})
}
}
}
}
Thanks
Review below examples which can help you to get table row values in LWC
https://salesforce.stackexchange.com/questions/273550/how-to-get-selected-row-data-from-lightning-datatable-in-salesforce-lwc
https://developer.salesforce.com/forums/?id=9062I000000IICYQA4
https://salesforce.stackexchange.com/questions/251100/lightning-web-component-for-table-rows-and-cells
Thanks,
Vinay Kumar