Thursday, 15 October 2020

SFDC LWC data table With Check Box

 public with sharing class OpportunityController {

   @AuraEnabled(cacheable=true)  

   public static List<opportunity> fetchRecordList(){  

     return [SELECT Id, Name, StageName,Amount From Opportunity LIMIT 5];  

   }  

   @AuraEnabled  

   public static void updateRecords(List<opportunity> recordList){  

     delete recordList;  

   }  

}

=====================================================================================================

import { LightningElement,track,wire } from 'lwc';

import {refreshApex} from '@salesforce/apex';  

import getAllRecords from '@salesforce/apex/OpportunityController.fetchRecordList';  

import updateRecords from '@salesforce/apex/OpportunityController.updateRecords';  

const COLS=[  

  {label:'Name',fieldName:'Name', type:'text'},  

  {label:'Stage',fieldName:'StageName', type:'text'},  

  {label:'Amount',fieldName:'Amount', type:'currency'}  

];  

export default class DataTableInLwcCheckbox extends LightningElement {

   cols=COLS;  

   @wire(getAllRecords) recordList;  

   deleteRecord(){  

     var selectedRecords =  

      this.template.querySelector("lightning-datatable").getSelectedRows();  

     updateRecords({recordList: selectedRecords})  

     .then(result=>{  

       return refreshApex(this.recordList);  

     })  

     .catch(error=>{  

       alert('Cloud not delete'+JSON.stringify(error));  

     })  

   }  

}

=====================================================================================================

<template>

    <lightning-card title="Opportunity">  

        <lightning-button variant="brand" slot="actions" label="Approve" onclick={deleteRecord}></lightning-button>  

        <div class="slds-box">  

          <lightning-datatable  

          data={recordList.data} columns={cols} key-field="Id">  

          </lightning-datatable>  

        </div>  

      </lightning-card>  

</template>


=====================================================================================================


No comments:

Post a Comment