You need to sign in to do that
Don't have an account?
Pedro Garcia G
aura:component respond a custom object
Hi...
I'm creating an aura component to load a CSV file pulled from a RESTFull server.
So, I need to pass the CSV header as a List<String> and the CSV body (columns and rows) as a List<List<String>>.
So, I decided to create an internal object in the controller for this.
I don't know and I appreciate your help to render this in the aura:component.
This is my helper
and this is a piece of my component
Thanks in advance.
I'm creating an aura component to load a CSV file pulled from a RESTFull server.
So, I need to pass the CSV header as a List<String> and the CSV body (columns and rows) as a List<List<String>>.
So, I decided to create an internal object in the controller for this.
public with sharing class CASCsvRecordsController { class CSVBody{ List<List<String>> csvRows {get;set;} List<String> csvHeader {get;set;} } @AuraEnabled public static CSVBody loadCSV(String csv){ //The CASConnector connect with a REST server and get the CSV as String String fullcsvbody = CASConnector.getCSV('293880', '419356'); CSVBody csvBodyObj = new CSVBody(); //This is List<String> of the CSV header csvBodyObj.csvRows = CASCsv.getCSVRows(fullcsvbody); //This is a List<List<String>> of the line & column csvBodyObj.csvHeader = CASCsv.getCSVHeader(fullcsvbody); return csvBodyObj; } }
I don't know and I appreciate your help to render this in the aura:component.
This is my helper
({ onLoad: function(component, event) { console.log('onLoad call'); //call apex class method var loadHeader = component.get('c.loadCSV'); loadHeader.setCallback(this, function(response) { //store state of response var state = response.getState(); if (state === "SUCCESS") { component.set('v.ListOfHeader', response.getReturnValue()); } else{ console.log("cas Failed with state: " + state); } }); $A.enqueueAction(loadHeader); }, })
and this is a piece of my component
<aura:component controller="CASCsvRecordsController" > <!--aura init handler , call js "loadContactList" function on component load, and display contact data on table--> <aura:handler name="init" value="{!this}" action="{!c.loadCsvList}"/> <aura:attribute name="ListOfHeader" type="List" />
Thanks in advance.
To implement the CSV download from the server, please take help from the following link, it consists of the code to download CSV file from the server.
http://sfdcmonkey.com/2017/04/19/download-csv-file-data-salesforce-lightning-component/
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
The sfdcmonkey sample is good, but it doesn't cover dynamics column in the file and the case where the value could be "something, something"
I'm still working on this... so, I appreciate any help.
Thanks,
Pedro