Monday, February 13, 2023

How To Add a New Record To Existing List Of Records in LWC JS Controller

Let's assume we are getting  list of records from the apex to js controller and for some reasons if we want to add new row how can we add to it we can see below.

import { LightningElement, api, track, wire } from "lwc";
import fetchActivities from "@salesforce/apex/CancelFlowCntrl.fetchCanActivities";

const columns = [
    { label: 'ticketvalue', fieldName: 'totalTicketvalue' },
    { label: 'refundedAmount', fieldName: 'totalRefundedAmount' },
    { label: 'cancellationCharges', fieldName: 'totCancellationCharges' },
    
];

export default class ActivitiesFlow extends LightningElement 
{
  
  @track allActivitiesData;
  
  @wire(fetchActivities, { recdId: '$sfrecordId' })
    wiredActivities({ error, data }) {
       if (data) 
       {
          this.allActivitiesData =  data;
		  var newItem = {"totalTicketvalue": 100,"totalRefundedAmount": 90,"totCancellationCharges":10};
		  this.allActivitiesData.push(newItem);

		}
		
		else if (error) {
            this.error = error;
            this.allActivitiesData = undefined;
           
        }
	}
 }


Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.


FaceBook Page - I Love Coding. You?


Hope this helps you..Enjoy..!

4 comments:


  1. Sosyal medya yönetimi konusunda güvenilir bir hizmet arıyorsanız en iyi smm panel ile tanışabilirsiniz. Bu panel kullanıcılarına çeşitli sosyal medya araçları ve hızlı hizmet seçenekleri sunarak işlerinizi kolaylaştırıyor. Ayrıca en iyi smm panel sayesinde takipçi ve etkileşim artırma süreçleriniz daha güvenli ve etkili hale geliyor. Böylece dijital varlığınızı güçlendirmek isteyenler için ideal bir tercih oluyor.

    ReplyDelete