1

I'm trying to add margins to my datatable which would be revenue minus cost.

Right now my code looks like this on the html.

<ng-container matColumnDef="margin">
      <mat-header-cell *matHeaderCellDef mat-sort-header>Margin</mat-header-cell>
      <mat-cell *matCellDef="let project">{{project.revenue - project.cost}}</mat-cell>
</ng-container>

The app shows the right number, but I'm not able to sort the column by ascending or descending order. I'm guessing because I'm calculating it in the HTML. How can I work around this?

1
  • Are you using PrimeNG data table? Commented Apr 19, 2018 at 7:39

1 Answer 1

5

You can calculate this in your controller.

The approach used by you is not the recommended way because the above calculation will happen with every change detection. But its possible that this value might only change once or on a particular action. So handling this in controller will avoid this and increase performance.

Sign up to request clarification or add additional context in comments.

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.