• Sidhartha Mohapatra 16
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
i have this below result from apex 
 
result =

    [  
       {  
          "Id":"0012v00002InPVmAAN",
          "Test__c":"India; Africa; Mombasa",
          "Test1__c":"AFR; TFR; GFR"
       }
    ]

i am able to generate csv as below -
"Id,Test__c,Test1__c
"0012v00002InPVmAAN","India; Africa; Mombasa","AFR; TFR; GFR"

i am want to create a csv file out of the above data, basically splitting semicolon separated values into multiple rows with other data
"Id,Test__c,Test1__c
"0012v00002InPVmAAN","India","AFR"
"0012v00002InPVmAAN","Africa","TFR"
"0012v00002InPVmAAN","Mombasa","GFR"

JS - 
 
downloadCSVFile() {
        let rowEnd = '\n';
        let csvString = '';
        // this set elminates the duplicates if have any duplicate keys
        let rowData = new Set();
        // getting keys from data
        this.data.forEach(function (record) {
            Object.keys(record).forEach(function (key) {
                rowData.add(key);
            });
        });
        // Array.from() method returns an Array object from any object with a length property or an iterable object.
        rowData = Array.from(rowData);
        // splitting using ','
        csvString += rowData.join(',');
        csvString += rowEnd;
        // main for loop to get the data based on key value
        for (let i = 0; i < this.data.length; i++) {
            let colValue = 0;

            // validating keys in data
            for (let key in rowData) {
                if (rowData.hasOwnProperty(key)) {
                    // Key value 
                    // Ex: Id, Name
                    let rowKey = rowData[key];
                    // add , after every value except the first.
                    if (colValue > 0) {
                        csvString += ',';
                    }
                    // If the column is undefined, it as blank in the CSV file.
                    let value = this.data[i][rowKey] === undefined ? '' : this.data[i][rowKey];
                    csvString += '"' + value + '"';
                    colValue++;
                }
            }
            csvString += rowEnd;
        }

 
I am trying to do page break in LWC. But it is not working. Below is the code. How to do page break in lightning while printing the page to pdf.
 
<template>
   <div>First Page</div>
   <div style="page-break-before: always;">Second page</div>
   <lightning-button label="Print" title="print" onclick={printpreview} class="printbutton"></lightning-button>&nbsp;&nbsp;
   <lightning-button label="Back" title="Back to record" onclick={back} class="back"></lightning-button>
</template>