hjalmers / angular-generic-table

A generic table for Angular 2+. Generic table uses standard markup for tables ie. table, tr and td elements etc. and has support for expanding rows, global search, filters, sorting, pagination, export to CSV, column clicks, custom column rendering, custom export values.
https://hjalmers.github.io/angular-generic-table/
MIT License
105 stars 55 forks source link

Export CSV and null or undefined values #274

Open thebigcosinus opened 5 years ago

thebigcosinus commented 5 years ago

Hi, I'm using the export function to csv but I get the text null in some cell, How can I prevent to get 'null' text and get an empty cell instead ? I would like to be global to all my tables. I don't whant to do it with the export key in each filed export: (row: Project) => row.value || ''

Thanks

hjalmers commented 5 years ago

I'm afraid the current version doesn't support global configuration but I was thinking about introducing it. One idea would be able to specify both settings and field configuration globally using an object key as an identifier.

So for example if you in your component have:

configObject = {
    settings: [{
            objectKey: 'id',
            sort: 'asc',
            sortOrder: 1,
            columnOrder: 0
        },
        {
            objectKey: 'name',
            sort: 'asc',
            sortOrder: 0,
            columnOrder: 1
        },
        {
            objectKey: 'date',
        }
    ],
    fields: [{
            name: 'Id',
            objectKey: 'id'
        },
        {
            name: 'Name',
            objectKey: 'name'
        },
        {
            objectKey: 'date',
        }
    ],
    data: []
}

You could specify the following in your global config:

globalConfig = {
    settings: [{
        objectKey: 'date',
        sort: 'desc'
    }],
    fields: [{
        name: 'Date'
        objectKey: 'date',
        export: (row: Row) => row.value || ''
    }],
    data: []
}

All table components using the objectKey date would then fetch the config for that field from the global config unless it's overridden by the "local" config. What do you think @thebigcosinus?

And perhaps the export function should have a null check too because I don't think there's any use case where you'd want to export null values as "null".