You need to sign in to do that
Don't have an account?
Aditi Mohanty 5
How to show a text message in action history column
When I click on "add to cart" the action history column should show "product added to cart" and same for "buy" button
Controller-- ({ doinit : function(component) { component.set( 'v.cols' , [ { label: 'Name', fieldName: 'Name', type: 'text' }, { 'label': 'Price', 'fieldName': 'Unitprice', 'type': 'Currency' }, { 'label': 'Action', 'type': 'button', 'typeAttributes': { 'label': 'Add to Cart', 'name': 'add to cart' } }, { 'label': 'Action', 'type': 'button', 'typeAttributes': { 'label': 'Buy', 'name':'buy' } }, { 'label': 'action history', 'fieldName': 'action history', 'type': 'text', 'value':'Edit' } ]); var action = component.get("c.getproduct"); action.setCallback(this, function(actionResult) { var state = actionResult.getState(); if (state === "SUCCESS") { var records = actionResult.getReturnValue(); for (var i = 0; i < records.length; i++) { records[i].Name = records[i].Product2.Name; records[i].Unitprice= records[i].UnitPrice; } component.set("v.productname", records); } }); $A.enqueueAction(action); }, onRowAction:function(component, event, helper) { var act = component.get("c.sendmail"); var getEmail = component.get("v.address"); var records = actionResult.getReturnValue(); act.setParams({ 'mMail': getEmail,}); var actionName = event.getParam('action').name; if(actionName=='add to cart'){ alert("product added to cart"); } if(actionName=='buy'){ alert("product will be delivered"); act.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { response.getReturnValue(); } }); } $A.enqueueAction(act); } }) Component-- <aura:component controller="products" > <aura:attribute name="productname" type="List"/> <aura:attribute name="cols" type="List"/> <aura:attribute name="address" type="string"/> <aura:attribute name="subject" type="string"/> <aura:attribute name="mailStatus" type="boolean" default="false"/> <aura:handler name="init" value="{!this}" action="{!c.doinit}"/> <lightning:datatable data="{!v.productname}" columns="{!v.cols}" keyField="Id" onrowaction="{!c.onRowAction}"/> </aura:component> apex code-- global with sharing class products { @AuraEnabled public static List<PricebookEntry> getproduct() { List<PricebookEntry> prod= [SELECT Product2.Name, Unitprice FROM PricebookEntry]; return prod; } @AuraEnabled public static void sendmail(String address, String subject, String body) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {'mohantyniki23@gmail.com'}; mail.setToAddresses(toAddresses); String message = 'Thank you choosing our service.Your package will be delivered in 5 days.'; mail.setSubject('Order confirmation'); mail.setPlainTextBody(message); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } }
Let me know if it helps