You need to sign in to do that
Don't have an account?
firstqa system
delete confirmation pop up message in lwc?
html
<template>
<lightning-card title="vehicle details">
<div class="slds-m-around_medium">
<lightning-button label="New vechile" onclick={navigateToNewvehiclePage}></lightning-button>
<lightning-input type="search" onchange={handleKeyChange} class="slds-m-bottom_small" label="Search"
value={searchKey}></lightning-input>
<lightning-datatable key-field="Id" data={data} columns={columns} sorted-by={sortedBy}
sorted-direction={sortedDirection} onsort={sortColumns} onrowaction={handleRowAction}>
</lightning-datatable>
</br>
<lightning-layout horizontal-align="space">
<lightning-layout-item flexibility="auto">
<lightning-button label="Previous" icon-name="utility:chevronleft" onclick={previousHandler}>
</lightning-button>
</lightning-layout-item>
<lightning-layout-item flexibility="auto">
Page {page} of {totalPage} total no of records-{totalRecountCount}
</lightning-layout-item>
<lightning-layout-item flexibility="auto">
<lightning-button label="Next" icon-name="utility:chevronright" icon-position="right"
onclick={nextHandler}></lightning-button>
</lightning-layout-item>
</lightning-layout>
</div>
</lightning-card>
</template>
--------------------------------------------------------------------------------------------
js
import { api, LightningElement, track, wire } from 'lwc';
import fetchvechile from '@salesforce/apex/viewapex.fetchvechile';
import { NavigationMixin } from 'lightning/navigation';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import {deleteRecord} from 'lightning/uiRecordApi';
import {refreshApex} from '@salesforce/apex';
const actions = [
{ label: 'View', name: 'view' },
{ label: 'Edit', name: 'edit' },
{ label: 'Delete', name: 'delete' },
];
const columns = [{ label: 'Name', fieldName: 'Name' },
{ label: 'RegNumber', fieldName: 'RegNumber__c' },
{ label: 'Model', fieldName: 'Model__c' },
{ label: 'Purchase Amount', fieldName: 'Purchase_Amount__c' },
{ label: 'Purchase Date', fieldName: 'Purchase_Date__c' },
{ label: 'Last Service', fieldName: ',Last_Service__c' },
{ label: 'NextserviceDate', fieldName: 'Next_service_Date__c' },
{
type: 'action',
typeAttributes: { rowActions: actions },
},
];
export default class DeleteContactLwc extends NavigationMixin( LightningElement ){
@track value;
@track error;
@track data;
@api sortedDirection = 'asc';
@api sortedBy = 'Name';
@api searchKey = '';
result;
@track page = 1;
@track items = [];
@track data = [];
@track columns;
@track startingRecord = 1;
@track endingRecord = 0;
@track pageSize = 5;
@track totalRecountCount = 0;
@track totalPage = 0;
@wire(fetchvechile, {searchKey: '$searchKey', sortBy: '$sortedBy', sortDirection: '$sortedDirection'})
wiredAccounts({ error, data }) {
if (data) {
this.items = data;
this.totalRecountCount = data.length;
this.totalPage = Math.ceil(this.totalRecountCount / this.pageSize);
this.data = this.items.slice(0,this.pageSize);
this.endingRecord = this.pageSize;
this.columns = columns;
this.error = undefined;
}
else if (error) {
this.error = error;
this.data = undefined;
}
}
navigateToNewvehiclePage() {
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'vehicle__c',
actionName: 'new',
},
});
}
//clicking on previous button this method will be called
previousHandler() {
if (this.page > 1) {
this.page = this.page - 1; //decrease page by 1
this.displayRecordPerPage(this.page);
}
}
nextHandler() {
if((this.page<this.totalPage) && this.page !== this.totalPage){
this.page = this.page + 1; //increase page by 1
this.displayRecordPerPage(this.page);
}
}
//this method displays records page by page
displayRecordPerPage(page){
this.startingRecord = ((page -1) * this.pageSize) ;
this.endingRecord = (this.pageSize * page);
this.endingRecord = (this.endingRecord > this.totalRecountCount)
? this.totalRecountCount : this.endingRecord;
this.data = this.items.slice(this.startingRecord, this.endingRecord);
this.startingRecord = this.startingRecord + 1;
}
sortColumns( event ) {
this.sortedBy = event.detail.fieldName;
this.sortedDirection = event.detail.sortDirection;
return refreshApex(this.result);
}
handleRowAction( event ) {
const actionName = event.detail.action.name;
const row = event.detail.row;
switch ( actionName ) {
case 'view':
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: row.Id,
actionName: 'view'
}
});
break;
case 'edit':
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: row.Id,
objectApiName: 'vehicle__c',
actionName: 'edit'
}
});
break;
case'delete':
this.recordId = event.target.value;
deleteRecord(row.Id)
.then(() =>{
const toastEvent = new ShowToastEvent({
title:'Record Deleted',
message:'Record deleted successfully',
variant:'success',
})
this.dispatchEvent(toastEvent);
refreshApex(this.result);
})
.catch(error =>{
window.console.log('Unable to delete record due to ' + error.body.message);
});
break;
default:
}
}
handleKeyChange( event ) {
this.searchKey = event.target.value;
return refreshApex(this.result);
}
}
this my javascript and html code to perform lighting data Table rowaction edit delete view with pagenation but problem is when i delete record it,s automatically delete the record without pop up msg.i need pop up message and when i perform edit operation table is not automatically updated .when i give refersh it will updated .soi need refersh it automatically.help me
thanks in advance
Email-arunkuppusamy001@gmail.com
mobile-9566594515 & 8328174785
<template>
<lightning-card title="vehicle details">
<div class="slds-m-around_medium">
<lightning-button label="New vechile" onclick={navigateToNewvehiclePage}></lightning-button>
<lightning-input type="search" onchange={handleKeyChange} class="slds-m-bottom_small" label="Search"
value={searchKey}></lightning-input>
<lightning-datatable key-field="Id" data={data} columns={columns} sorted-by={sortedBy}
sorted-direction={sortedDirection} onsort={sortColumns} onrowaction={handleRowAction}>
</lightning-datatable>
</br>
<lightning-layout horizontal-align="space">
<lightning-layout-item flexibility="auto">
<lightning-button label="Previous" icon-name="utility:chevronleft" onclick={previousHandler}>
</lightning-button>
</lightning-layout-item>
<lightning-layout-item flexibility="auto">
Page {page} of {totalPage} total no of records-{totalRecountCount}
</lightning-layout-item>
<lightning-layout-item flexibility="auto">
<lightning-button label="Next" icon-name="utility:chevronright" icon-position="right"
onclick={nextHandler}></lightning-button>
</lightning-layout-item>
</lightning-layout>
</div>
</lightning-card>
</template>
--------------------------------------------------------------------------------------------
js
import { api, LightningElement, track, wire } from 'lwc';
import fetchvechile from '@salesforce/apex/viewapex.fetchvechile';
import { NavigationMixin } from 'lightning/navigation';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import {deleteRecord} from 'lightning/uiRecordApi';
import {refreshApex} from '@salesforce/apex';
const actions = [
{ label: 'View', name: 'view' },
{ label: 'Edit', name: 'edit' },
{ label: 'Delete', name: 'delete' },
];
const columns = [{ label: 'Name', fieldName: 'Name' },
{ label: 'RegNumber', fieldName: 'RegNumber__c' },
{ label: 'Model', fieldName: 'Model__c' },
{ label: 'Purchase Amount', fieldName: 'Purchase_Amount__c' },
{ label: 'Purchase Date', fieldName: 'Purchase_Date__c' },
{ label: 'Last Service', fieldName: ',Last_Service__c' },
{ label: 'NextserviceDate', fieldName: 'Next_service_Date__c' },
{
type: 'action',
typeAttributes: { rowActions: actions },
},
];
export default class DeleteContactLwc extends NavigationMixin( LightningElement ){
@track value;
@track error;
@track data;
@api sortedDirection = 'asc';
@api sortedBy = 'Name';
@api searchKey = '';
result;
@track page = 1;
@track items = [];
@track data = [];
@track columns;
@track startingRecord = 1;
@track endingRecord = 0;
@track pageSize = 5;
@track totalRecountCount = 0;
@track totalPage = 0;
@wire(fetchvechile, {searchKey: '$searchKey', sortBy: '$sortedBy', sortDirection: '$sortedDirection'})
wiredAccounts({ error, data }) {
if (data) {
this.items = data;
this.totalRecountCount = data.length;
this.totalPage = Math.ceil(this.totalRecountCount / this.pageSize);
this.data = this.items.slice(0,this.pageSize);
this.endingRecord = this.pageSize;
this.columns = columns;
this.error = undefined;
}
else if (error) {
this.error = error;
this.data = undefined;
}
}
navigateToNewvehiclePage() {
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'vehicle__c',
actionName: 'new',
},
});
}
//clicking on previous button this method will be called
previousHandler() {
if (this.page > 1) {
this.page = this.page - 1; //decrease page by 1
this.displayRecordPerPage(this.page);
}
}
nextHandler() {
if((this.page<this.totalPage) && this.page !== this.totalPage){
this.page = this.page + 1; //increase page by 1
this.displayRecordPerPage(this.page);
}
}
//this method displays records page by page
displayRecordPerPage(page){
this.startingRecord = ((page -1) * this.pageSize) ;
this.endingRecord = (this.pageSize * page);
this.endingRecord = (this.endingRecord > this.totalRecountCount)
? this.totalRecountCount : this.endingRecord;
this.data = this.items.slice(this.startingRecord, this.endingRecord);
this.startingRecord = this.startingRecord + 1;
}
sortColumns( event ) {
this.sortedBy = event.detail.fieldName;
this.sortedDirection = event.detail.sortDirection;
return refreshApex(this.result);
}
handleRowAction( event ) {
const actionName = event.detail.action.name;
const row = event.detail.row;
switch ( actionName ) {
case 'view':
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: row.Id,
actionName: 'view'
}
});
break;
case 'edit':
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: row.Id,
objectApiName: 'vehicle__c',
actionName: 'edit'
}
});
break;
case'delete':
this.recordId = event.target.value;
deleteRecord(row.Id)
.then(() =>{
const toastEvent = new ShowToastEvent({
title:'Record Deleted',
message:'Record deleted successfully',
variant:'success',
})
this.dispatchEvent(toastEvent);
refreshApex(this.result);
})
.catch(error =>{
window.console.log('Unable to delete record due to ' + error.body.message);
});
break;
default:
}
}
handleKeyChange( event ) {
this.searchKey = event.target.value;
return refreshApex(this.result);
}
}
this my javascript and html code to perform lighting data Table rowaction edit delete view with pagenation but problem is when i delete record it,s automatically delete the record without pop up msg.i need pop up message and when i perform edit operation table is not automatically updated .when i give refersh it will updated .soi need refersh it automatically.help me
thanks in advance
Email-arunkuppusamy001@gmail.com
mobile-9566594515 & 8328174785
Do you see any error in the browser's dev tools in case of deleting the records but does not refresh the table in LWC? Check the similar post https://salesforce.stackexchange.com/questions/247252/i-am-clicking-delete-record-and-record-are-getting-deleted-but-it-does-not-refre
According to this properties decorated with @api are read-only to the component; the parent component controls the value. That makes your change to this.elements a noop and thus you don't observe the change.
You might want to add a Refresh button & call your apex on click of it. So you will get an updated List every time.
If this information helps, please mark the answer as best.Thank you
show me your apex file.
Thank you
@AuraEnabled(cacheable=true)
public static List < vehicle__c> fetchvechile(String searchKey, String sortBy, String sortDirection) {
return[ SELECT Id, Name,RegNumber__c,Model__c,Purchase_Amount__c,Purchase_Date__c,Last_Service__c,Next_service_Date__c FROM vehicle__c];
}
}
this is my apex code
thanks for response