ssuperczynski / ngx-easy-table

The Easiest Angular Table. 12kb gzipped! Tree-shakeable. 55 features and growing!
https://ngx-easy-table.eu
MIT License
371 stars 100 forks source link

How to show column (array of data) #319

Closed chhinsras closed 4 years ago

chhinsras commented 4 years ago

I have

export interface Call {
  id?: number;
  acceptCall: boolean;
  callReasons: CallReason[];
}

export interface CallReason {
  callId: number;
  name: string;
}

// This is column configuration

 this.columns = [
  { key: 'id', title: 'Id', width: '5%'},
  { key: 'callClients.name', title: 'Clients', width: '7%'}, /// it is not showing anything
  { key: 'acceptCall', title: 'Accept Call', width: '3%' },
];
ssuperczynski commented 4 years ago

You are trying to access callClients.name, but the Call interface doesn't have callClients property. Is it a typo?

chhinsras commented 4 years ago

You are trying to access callClients.name, but the Call interface doesn't have callClients property. Is it a typo?

it is not typo.

it is 'callReasons.name'

is it possible to access the array

// this is my actual response from server.

[
    {
        "id": 17,
        "acceptCall": true,
        "callClients": [
            {
                "id": 12,
                "name": "Mean thormi",
            },
            {
                "id": 10,
                "name": "Borarey",
            }
        ],
        "callReasons": [
            {
                "id": 46,
                "name": "Support Transportation"
            },
            {
                "id": 22,
                "name": "Buy Food"
            }
        ]
    },
    {
        "id": 16,
        "acceptCall": true,
        "callClients": [
            {
                "id": 12,
                "name": "Mean thormi",
            },
            {
                "id": 10,
                "name": "Borarey",
            }
        ],
        "callReasons": [
            {
                "id": 46,
                "name": "Support Transportation"
            },
            {
                "id": 22,
                "name": "Buy Food"
            }
        ]
    }
]
chhinsras commented 4 years ago

This is what I am thinking of // { key: 'callClients.map(c => c.nameKH)', title: 'Clients', width: '7%'}

But not working

ssuperczynski commented 4 years ago

You need to build your own column template, since it is an array, not an object.

https://github.com/ssuperczynski/ngx-easy-table/blob/master/src/app/demo/col-template/col-template.component.html

chhinsras commented 4 years ago

I still cannot figure it out.

Could you show me how to use this template?

chhinsras commented 4 years ago

Screen Shot 2020-10-06 at 3 29 56 PM

I followed you and it showed object

chhinsras commented 4 years ago

I need to manual type the template copied from this repo to work.

<ng-template #clientTbl let-row let-rowIndex="rowIndex"> <div *ngFor="let item of row.callClients">

{{item.name}}