zheeeng/export-from-json

How to customise column header before export ?

html-helpers opened this issue · 4 comments

Hello,

How to customise column header ?

For eg. I want my header should be like First Name, but data from it should read value is firstName. So, currently it is displaying firstName as column header in my exported CSV file but I want as 'First Name'.

Thanks,

Hi, thx for using it.

We provided a hook to access the data before exporting. Plz reference the https://github.com/zheeeng/export-from-json#types chapter and use beforeTableEncode.

We also made a test as the example https://github.com/zheeeng/export-from-json/blob/master/__tests__/createTableEntries.spec.ts#L12-L16

Appreciate quick response...!!!

Going throgh example, it is not quite clear in what we need to pass and how we need to use this attribute.

Do we need to set this as method and then we need to alter table entries in method ?

Thanks,

Yes, let me show you the usage for transforming the raw output:

{
  beforeTableEncode: entries => entries.map(
    ({ fieldName, fieldValues }) => ({ fieldName: formatTitle(fieldName), fieldValues })
  )
}

Thank you very much for sample. I am able to customise column header before exporting the CSV file.

Thanks