1

Hi I have been using this tag to change my css style, if the condition totalAsset and sortedAsset are same

<div class="table-row" ng-repeat="x in myData" ng-click="sort()" 
ng-class="{'lightblue': x.totalAsset == sortedAsset}">

totalAsset is my data in like this

$scope.myData = [
{
totalAsset: "23557"
},
{
totalAsset: "4512190",   
},
{
totalAsset: "2190",   
},
{
totalAsset: "1256790",   
}
]

i have create a function that self sort the totalAsset

$scope.sort = function (){
$scope.unsortedAsset = $scope.myData.totalAsset;
$scope.sortedAsset=$scope.unsortedAsset.split("").sort().join("");
}

in the logic only the first and last row will become blue the other two rows remain same.

1 Answer 1

0

In sort() you directly access $scope.myData.totalAsset. This gets resolved as a reference to the last object in $scope.myData that has a totalAsset member.

Instead you wanted to iterate over all objects in myData. That can be achieved by supplying a parameter to the sort function like in the code below.

$scope.sort = function (totalAsset){
    $scope.unsortedAsset = totalAsset;
    $scope.sortedAsset=$scope.unsortedAsset.split("").sort().join("");
}

Then you also must call the sort function by supplying the parameter value.

<div class="table-row" ng-repeat="x in myData" ng-click="sort(x.totalAsset)" ng-class="{'lightblue': x.totalAsset == sortedAsset}">
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I still have a bug in my code, that is there are many result in my data but ng-click only give a true/false when i click on the certain item. How can I use ng-click to click one time on my table to display all the true table rows?
Actually that´s a quite different question. I suggest you ask that as a new SO question.

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.