0

Using angularjs

I have 3 select dropdowns and a button to get a json list

Focus select dropdown looks like this:

<select id='sort' ng-model='sort'>
  <option value='1'>ID</option>
  <option value='2'>Departmentname</option>
  <option value='3'>Number of employees</option>
</select>
<button ng-click="getinfo()">GET INFO</button>

The table looks like this

<table>
<tr> <td>{{ depid }}</td> <td>{{ depname }}</span></td> <td>{{ depemp }}</td></tr>

In the controller I have:

$scope.depid = "Department id";
$scope.depname = "Departmentname";
$scope.depemp = "Number of employees";

$scope.getinfo = function() {
  var url = "";  
  ...
}

Based on selection "sort" I want the sort column to be bold/strong or uppercase.

How do I do thIS?

2 Answers 2

2

You can use ng-class on the td elements:

<tr> 
    <td ng-class="{bold : sort == 1}">{{ depid }}</td> 
    <td ng-class="{bold : sort == 2}">{{ depname }}</span></td> 
    <td ng-class="{bold : sort == 3}">{{ depemp }}</td>
</tr>

And add a CSS rule:

.bold { 
    font-weight: bold;
}

Here's a Fiddle demonstration.

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

2 Comments

After testing the header becomes bold before loading the table in the correct sort order. The change must come from within the controller. Any idea?
After the getInfo function set a new variable as the value of the sort... call it something like sortedBy so if getInfo is a promise then do getInfoPromise.then(function(){sortedBy = sort})
0

Following Omri Aharon I changed ng-class="{bold : sort == 1}" to ng-class="{bold : sortby == 1}" and followed Nayish I put following inside controller $scope.getinfo = function() { var url = "";
... $http.get(url) .success(function(response) { $scope.names = response; $scope.sortby = $scope.sort;}); }

Thanks a lot to the two of you!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.