alhazmy13 / angular-csv-ext

Helper library for create CSV file in Angular.
MIT License
45 stars 23 forks source link

Feature added to pass header object with key and value of header #49

Closed ryndm closed 3 years ago

ryndm commented 3 years ago

Often times the data object keys and the header names are not same. So I've added option to pass header in the form of object. The keys would be same as that of the keys of the data to be shown and the value would be used as the header of the column for that key. Also the sequence of keys don't matter. They will be ordered according the the header object passed.

For example :

data  = [
  { sr_no: 1, name: 'test', age: 22 },
  { sr_no: 2, name: 'test22', addr: 'CA', age: 20 }
]

In above array one object has addr field missing. So age would be shown in addr's column with the current implementation. Also I would like addr's column header name to be 'Address' and sr_no to be 'Sr. no'. To handle this scenario's I've made some changes. Please go through them.

For the above data, header object would be

objHeader = {
  sr_no: 'Sr. no',
  name: 'Name',
  addr: 'Address',
  age: 'Age'
}

and to use this object one needs to pass useObjHeader: true with the above objHeader