function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anil Kumaranil Kumar 

How to show and hide columns and based other column value in the CSV file

Hi All,

We have implemented download all the Assest object records in the CSV file based on the button click in the lightning compnent. Now i need show and hide columns and based other column value in the CSV file.

For example if the column A value equals source i need to hide column E and F in the CSV file and column A value not equals source i need to show column E and F in the CSV.

Below is the code which we have used in component JS to dlownload all the records.

  downloadCsvrecords : function(component,event,helper){
        var lstPositions = component.get("v.fullResults");
        console.log('lstPositions=== : '+ lstPositions.length);
        var data = [];
        var headerArray = [];
        var csvContentArray = [];        
        //Fill out the Header of CSV
        //headerArray.push('Installed Product');
        headerArray.push('Product Line');
        headerArray.push('Serial Number');
        headerArray.push('System ID / Asset#'); 
        headerArray.push('Remote Access');
        for(var i=0;i<lstPositions.length;i++){
            //Check for records selected by the user
                console.log('lstPositions.length : '+ lstPositions.length);
                //Initialize the temperory array
                var tempArray = [];
                //use parseInt to perform math operation
                if(lstPositions[i].Product_Line__c === undefined || lstPositions[i].Product_Line__c == null){
                if(lstPositions[i].Serial_Lot_Number__c === undefined || lstPositions[i].Serial_Lot_Number__c == null){
                if(lstPositions[i].Asset_Tag__c === undefined || lstPositions[i].Asset_Tag__c == null){
                if(lstPositions[i].SM_Eligibility_Status__c === undefined || lstPositions[i].SM_Eligibility_Status__c ==  null){tempArray.push('"'+''+'"');
                if(lstPositions[i].SM_VirtualCare_Enabled__c === undefined || lstPositions[i].SM_VirtualCare_Enabled__c == null){tempArray.push('"'+''+'"');
                if(lstPositions[i].Site__c === undefined || lstPositions[i].Site__c == null){
        console.log('data.length : '+ data.length);
        for(var j=0;j<data.length;j++){
            var dataString = data[j].join(",");
        var csvContent = csvContentArray.join("\n");
        var fileName = "My Assets"; //Generate a file name
        fileName += ".csv";            //this will remove the blank-spaces from the title and replace it with an underscore 
        if (navigator.msSaveBlob) { // IE 10+
            var blob = new Blob([csvContent],{type: "text/csv;charset=utf-8;"});
            navigator.msSaveBlob(blob, fileName);
          var myBlob =  new Blob( [csvContent] , {type: 'text/html'});
         var url = window.URL.createObjectURL(myBlob);
         var a = document.createElement("a");
         a.href = url; = "My Assets.csv";;
        //adding some delay in removing the dynamically created link solved the problem in FireFox
         setTimeout(function() {window.URL.revokeObjectURL(url);},0);

Anil Kumar