how to display an object in one row of smart table

914 Views Asked by At

entity from MongoDB enter image description here

I want to display those 3 attributes "currencyCode, Amount, serialData" in one case of table.

I'm using ng2-smart-table with angular 11 and I'm try this code but nothings work

      dateTime: {
        title: 'Date & Time',
      },
      montant: {
        title: 'Montant',
      },      
      serialNbr: {
        title: 'serialNbr',
          CurrencyCode: {
            valuePrepareFunction: (row) => { return row.serialNbr.CurrencyCode }
          },
          Amount: {
            valuePrepareFunction: (row) => { return row.serialNbr.Amount }
          },
          SerialData: {
            valuePrepareFunction: (row) => { return row.serialNbr.SerialData }

          },
      },

2

There are 2 best solutions below

0
On BEST ANSWER

i fix my issue perfectly and i share this code to help anyone else have the same problem, if you have a nested field or a field that is an array of objects enter image description here

dateTime: {
        title: 'Date & Time',
      },
      montant: {
        title: 'Montant',
      },      
      serialNbr: {
        title: 'Serial Number',
        valuePrepareFunction: (serialNbr) => {
          return serialNbr.map(s => "" + s.CurrencyCode + ","+s.Amount+","+s.SerialData+" ").toString()
        }  
      },

5
On

According to the documentation

valuePrepareFunction - function run against a value before it gets inserted into a cell. You can use it to modify how a value is displayed in the cell. This function will be invoked with 2 parameters: cell, row Documentation

I think you should change your code in the following

    serialNbr: {
        title: 'serialNbr',
         valuePrepareFunction: (cell, row) => {
           return `${row.serialNbr.CurrencyCode} ${row.serialNbr.Amount } ${row.serialNbr.SerialData }` 
        },
      },