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.

Home Page:https://hjalmers.github.io/angular-generic-table/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export CSV and null or undefined values

thebigcosinus opened this issue · comments

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

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".