I have a table that uses Angular orderby. I use a function called tcoSort that makes a calculation and then sorts the table. The problem is when I call displayFullPricing() from the radio button in the rows - the table loses the sorting.
<table class="table table-striped table-hover">
<tr ng-repeat="prices in productVariant.prices | orderBy: tcoSort">
<td>£{{prices.monthly.retailPrice}}</td>
<td>£{{prices.nonRecurring.retailPrice | number:0}}</td>
<td><input type="radio" name="{{productVariant.code}}" ng-click="displayFullPricing($index)"></td>
</tr>
$scope.tcoSort = function (productVariant) {
if(!$scope.isDisplayPrice){
return productVariant.nonRecurring.retailPrice + (productVariant.monthly.retailPrice * 36);
}
};
$scope.displayFullPricing = function (index) {
$scope.isDisplayPrice = true; //This is to stop the table sort running more than once.
I put this here to act as a flag as everytime this function was called from the radio button, tcoSort would fire again and sort the table.
This meant that the radio button would only work once.
//rest of code
}
I guess the issue is that I am creating the flag to stop the sort happening every time I click a radio button in the table. But If i don't put it there, the $index is always set to the top result - so it would always be 0.