Jose the hose
Jose the hose

Reputation: 1895

Table sorting with calculated value in a column cell with angular

I was wondering how I can sort a table on a column cell that has been calculated.

For example, in the table below, how would I sort the TCD column so that the lowest value is displayed at the top of the table? As there is a calculation in the cell I'm not sure how to do it.

<table class="table table-striped table-hover">
<thead>
<th>MD</th>
<th>TCD</th>
</thead>
<tbody>
<tr  ng-repeat="product in selectedProductPrices">
    <td>£{{ product.RecurringCost  | number:2}}</td>
    <td>£{{ product.OneOffCost + product.OneOffCostMargin + ((product.RecurringCost + product.RecurringCostMargin) * productAttributesObj.Term) | number:2}}</td>
</tr>
</tbody>

Upvotes: 3

Views: 935

Answers (1)

squiroid
squiroid

Reputation: 14017

You need custom orderBy Example

<tr  ng-repeat="product in selectedProductPrices|orderBy:myValueFunction">

In controller:-

$scope.myValueFunction = function(product) {
   return product.OneOffCost + product.OneOffCostMargin + ((product.RecurringCost + product.RecurringCostMargin) * productAttributesObj.Term);
};

Upvotes: 4

Related Questions