Ng2 smart table,从一个对象中获取多个列

Ng2 smart table, getting multiple columns from one object

我正在使用 ng2 智能列来显示包含用户对象的交易。 我想在不同的列中显示 id 用户、姓名和电子邮件。 我该怎么做?

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',
      },
    },
  };

检查这个link https://stackblitz.com/edit/example-ng2-smart-table-ytzrns?file=src/app/app.component.ts

您可以引用同一对象的不同属性,只需在 valuePrepareFunction 中获取整行。我将通过以下示例向您展示

...

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;
    },
},
...

希望我的回答足够清楚。有需要就问。

干杯

这就是解决方案

  
   '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