简体   繁体   English

Ng2 智能表,从一个对象获取多列

[英]Ng2 smart table, getting multiple columns from one object

I'm using ng2 smart column to show transactions which contain an user object.我正在使用 ng2 智能列来显示包含用户对象的交易。 I want to display the id user, name, and email in different columns.我想在不同的列中显示 id 用户、姓名和电子邮件。 How can I do it?我该怎么做?

 settings = { add: { addButtonContent: '<i class="nb-plus"></i>', createButtonContent: '<i class="nb-checkmark"></i>', cancelButtonContent: '<i class="nb-close"></i>', confirmCreate : true }, edit: { editButtonContent: '<i class="nb-edit"></i>', saveButtonContent: '<i class="nb-checkmark"></i>', cancelButtonContent: '<i class="nb-close"></i>', confirmSave : true }, delete: { deleteButtonContent: '<i class="nb-trash"></i>', confirmDelete: true, }, columns: { id: { title: 'ID', type: 'number', }, user: { title : 'name', valuePrepareFunction: (data) => { return data.email; }, }, amount: { title: 'Valeur', type: 'number', }, items: { name: { title: 'Nom' }, }, state: { title: 'Etat', type: 'string', }, delivery_date: { title: 'Date de livraison', type: 'string', }, expedition_date: { title: 'Date d\\'expedition', type: 'string', }, }, };

check it on this link https://stackblitz.com/edit/example-ng2-smart-table-ytzrns?file=src/app/app.component.ts在此链接上查看https://stackblitz.com/edit/example-ng2-smart-table-ytzrns?file=src/app/app.component.ts

this is the solution这是解决方案

 'user.firstName': { title: 'Name', valuePrepareFunction: (cell, row) => { return row.user.firstName } }, 'user.lastName': { title: 'Last name', valuePrepareFunction: (cell, row) => { return row.user.lastName } }, 'user.address': { title: 'address', valuePrepareFunction: (cell, row) => { return row.user.address } }, 'user.email': { title: 'email', valuePrepareF

you can refer different properties of the same object just getting the entire row in valuePrepareFunction.您可以引用同一对象的不同属性,只需在 valuePrepareFunction 中获取整行即可。 I'll show you with the following example我将通过以下示例向您展示

...

property1: {
    title: 'Colum 1 title',
    type: 'string',
    valuePrepareFunction: (cell, row) => {
      return row.object.property1;
    },
},
property2: {
    title: 'Cell 2 title',
    type: 'string',
    valuePrepareFunction: (cell, row) => {
      return row.object.property2;
    },
},
...

I hope my answer is clear enough.我希望我的回答足够清楚。 Ask if needed.需要的话请教。

Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM