Skip to content

Missing column in row if column value is empty string #75

@noumanbhatti

Description

@noumanbhatti

I'm exporting data to CSV in Angular Reactive Forms.

My code in the .ts file is like

let data: BatchListCSV[]=[];
let obj: BatchListCSV = new BatchListCSV();
                    obj.created_date = new Date(b.created_date).toLocaleDateString();
                    obj.batch_type = b.batch_type;
                    obj.client_reference = b.client_reference;
                    obj.device_uid = b.device_uid;
                    obj.user_id =  b.user_id;
                    obj.ticket_count = b.ticket_count;

                    data[this.index] = obj;

this.csvData = data;
                
                this.csvOptions = {
                    headers: ['Date Created', 'Batch Type', 'Client Reference', 'Device UID','User', 'Ticket Count'], filename: 'Batches', fieldSeparator: ','
                    , quoteStrings: '"', decimalseparator: '.', showLabels: false, keys: [], removeNewLines: false, showTitle: false, title: '', useBom:false
                };

The sample data looks like

BatchListCSV {created_date: "10/31/2018", batch_type: "Tickets Created", client_reference: "5735", device_uid: "ipas_00e0c535be00", user_id: "", ticket_count: 1}
BatchListCSV {created_date: "10/31/2018", batch_type: "Tickets Created", client_reference: "Jayco Bendigo Cup (Featuring Mental As Anything)_311018.csv", device_uid: "", user_id: "a.hearps@bendigo.countryracing.com.au",ticket_count: 400}
BatchListCSV {created_date: "10/31/2018", batch_type: "Tickets Created", client_reference: "5748", device_uid: "ipas_00e0c535be00", user_id: "",ticket_count: 5}

When exported to CSV, for empty strings data like for user_id & device_uid in the data above. It ignores the empty string and uses the next column data instead. I want to show the empty string as it is for that column.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions