You need to sign in to do that
Don't have an account?
rohan patel 30
lwc data is not visible in datatable :
html code: <template> <lightning-card title="imprative Demo"> <div style="height: 300px;"> <lightning-datatable key-field="id" data={data} columns={columns}> </lightning-datatable> </div> </lightning-card> </template> js code : import { LightningElement ,track} from 'lwc'; import getcontacts from '@salesforce/apex/mperativeDemo.getcontacts'; const columns=[ {label: 'record id', fieldname: 'Id'}, {label:"contact Name" ,fieldname:'Name'}, ]; export default class ImperativeDemo extends LightningElement { @track columns=columns; @track data=[]; connectedCallback(){ getcontacts() .then(result=>{ //then is a promise in js this.data=result; }) .catch(error=>{ console.log("error occured"); }) } } apex class: public class mperativeDemo { @AuraEnabled public static list<contact> getcontacts(){ list<contact> getlist=[select id,name from contact]; return getlist; } }
Refer the below link and modify your code.
https://www.sfdcpoint.com/salesforce/lightning-web-component-lightning-datatable/
Still facing issues let me know will help you with code.
Thanks!!
<lightning-card title="imprative Demo">
<div style="height: 300px;">
<lightning-datatable
key-field="id"
data={data}
columns={columns}>
</lightning-datatable>
</div>
</lightning-card>
</template>
js code :
import { LightningElement ,track} from 'lwc';
import getcontacts from '@salesforce/apex/mperativeDemo.getcontacts';
const columns=[
{label: 'record id', fieldname: 'id'},
{label:"contact Name" ,fieldname:'name'},
];
export default class ImperativeDemo extends LightningElement {
@track columns=columns;
@track data=[];
connectedCallback(){
getcontacts()
.then(result=>{ //then is a promise in js
this.data=result;
})
.catch(error=>{
console.log("error occured");
})
}
}
apex class:
public class mperativeDemo {
@AuraEnabled
public static list<contact> getcontacts(){
list<contact> getlist=[select id,name from contact];
return getlist;
}
}