scania / corporate-ui

This repo will be archived in Q3 2021, please visit https://github.com/scania-digital-design-system
https://digitaldesign.scania.com/
25 stars 15 forks source link

Bug - c-table doesn't work when data has nested properties #573

Closed corte closed 4 years ago

corte commented 4 years ago

Describe the bug
When using the new c-table with sort and filter functionality, if we use complex objects, the component fails to show values.

To Reproduce
Have a complex object with nested properties, for example:

[
    {
        "name": "P. Sherman",
        "address": {
             "street": "Wallaby Way",
             "number": 42,
             "city": "Sydney"
        }
    }
]

Create a c-table that will display "name" and "city":

let table = document.querySelector('c-table');
table.header = [
    {
        key: "name",
        description: "Name",
    },
    {
        key: "address.city", // Note the '.' accessing a subproperty
        description: "City",
    }
];

The field city will not show anything and the filter functionality will be broken: image

Expected behavior
Subproperty should be fetched and shown in the UI. In the example mentioned above, it should show Sydney.

Screenshots
See above

Version of Corporate-ui
4.1.2-1

Framework and version
If you use any specific framework please provide information

Application link
Not implemented in any applications

Desktop information:
Please complete the following information

Additional context
A temporary work-around is mapping the object to a flat structure before showing the data. eg:

data.map(item => ({ "name": item.name, "city": item.address.city }))