Reputation: 45
I'm trying to create a table with Angular that has headers that can set the order, so far it's working but it only sets the order once.
I have used console.log and the variable is changing.
Table
<table class="table table-striped table-bordered">
<thead>
<tr>
<th ng-click="setOrder('iss.issueID')"> ID</th>
<th ng-click="setOrder('iss.issueTitle')" >Issue</th>
<th ng-click="setOrder('iss.zone')">Zone</th>
<th ng-click="setOrder('iss.type')">Type</th>
<th ng-click="setOrder('iss.time')">Time</th>
<th ng-click="setOrder('iss.userID')">User ID</th>
<th ng-click="setOrder('iss.user')">User</th>
</tr>
</thead>
<tbody>
<tr ng-repeat= "iss in issues | filter:name | orderBy:order">
<td>{{ iss.issueID }}</td>
<td>{{ iss.issueTitle }}</td>
<td>{{ iss.zone }}</td>
<td>{{ iss.type }}</td>
<td>{{iss.time * 1000 | date:'yyyy-MM-dd HH:mm:ss '}}</td>
<td>{{ iss.userID }}</td>
<td>{{ iss.user }}</td>
</tr>
</tbody>
</table>
Function
$scope.issues = [
<? php
$result = mysqli_query($con, $qr);
while ($row = mysqli_fetch_array($result)) {
echo "{issueID: '".$row['issueID']."',
user: '".$row['firstName'].' '.$row['lastName']."',
userID: '".$row['userID']."',
issueTitle: '".$row['issue']."',
issueDesc: '".$row['issueDesc']."',
time: '".$row['timeReceived']."',
machine: '".$row['machineID'].' '.$row['manufacturer'].' '.$row['machineType']."',
zone: '".$row['zoneID'].' '.$row['Location'].' '.$row['Name']."',
type: '".$row['type']."',
technician: '".$row['techID']." ".$row['tfirstName']." ".$row['tlastName']."'";
echo "},";
}
?>
];
$scope.setOrder = function (order) {
$scope.order = order;
console.log($scope.order = order);
};
});
Upvotes: 0
Views: 46
Reputation: 195972
You are passing the wrong value to the setOrder
function.
You should remove the iss.
part. You only need the actual key names of the object.
<tr>
<th ng-click="setOrder('issueID')"> ID</th>
<th ng-click="setOrder('issueTitle')" >Issue</th>
<th ng-click="setOrder('zone')">Zone</th>
<th ng-click="setOrder('type')">Type</th>
<th ng-click="setOrder('time')">Time</th>
<th ng-click="setOrder('userID')">User ID</th>
<th ng-click="setOrder('user')">User</th>
</tr>
Demo at http://plnkr.co/edit/Afh8ha5F7zBgGa2CaO4o?p=preview
Upvotes: 2