angulartypescript2.0ng2-smart-table

Ng2 smart table, getting multiple columns from one object


I'm using ng2 smart column to show transactions which contain an user object. I want to display the id user, name, and email in different columns. 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


Solution

  • 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