0

I was trying the example of material 2 table as explained in this tutorialand it worked nice.

My problem is that in their api or example they have nowhere mention of to combine 2 separate columns to one single column.

I have having this data..

  1. Column 1 - User ID
  2. Columns 2 - First name
  3. Columns 3 - Last name
  4. Column 4 - Address

I want to a new columns which will replace Column2 and Column3 (i.e want to make new column with name Full Name which will be Coulmn2 + column3 )

Is there any way so that i can achieve the desired functionality. I dont want to edit the data at server side for this. this should be only done via frontend.

2 Answers 2

1

As an alternative, map your server data into the object format you want to use:

interface User {
  id: string;
  firstName: string;
  lastName: string;
  address: string;
}

interface UserDisplay {
  id: string;
  fullName: string;
  address: string;
}

const displayUsers: UserDisplay[] = this.getAllUsers()
  .map(user => {
    return {
      id: user.id,
      fullName: `${firstName} ${lastName}`,
      address: user.address,
    }
  });
Sign up to request clarification or add additional context in comments.

Comments

1

You can concatenate values of several columns inside the moustache binding:

<md-cell *mdCellDef="let row"> {{row.id.toString() + ' ' + row.name.toString()}} </md-cell>

See the plunk.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.