Angular SortableTable
Using directive
by maxisam
HTML
<table ng:controller="SortableTableCtrl">
<thead>
<tr>
<th ng:repeat="(col, hdg) in head">
<span >{{hdg}}</span>
</th>
</tr>
</thead>
<tbody>
<tr ng:repeat="row in body | orderBy:selected:reverse">
<td>{{row.a}}</td>
<td>{{row.b}}</td>
<td>{{row.c}}</td>
</tr>
</tbody>
</table>
CSS
td { padding: 0.2em 1em; }
th { text-align: center; cursor: pointer; }
th span { padding-right: 2px; } /* gap so asc/desc images are not flush */
thead {
border-bottom: 2px solid black;
cursor: pointer;
}
/* http://www.greywyvern.com/code/php/binary2base64 */
th {
min-width: 100px;
text-align: center;
}
span.desc:after {
content:...
JavaScript
var myModule = angular.module('demo', []);
function SortableTableCtrl(scope) {
// defaults
scope.reverse = false;
scope.selected = 'a';
// model
scope.head = {
a: "Name",
b: "Surname",
c: "City"
};
scope.body = [
{
a: "Hans",
b: "Mueller",
c: "Leipzig"},
{
a: "Dieter",
b: "Zumpe",
c: "Berlin"},
{
a: "Bernd",
b: "Danau",
c: "Muenchen"}
];
}
SortableTableCtrl.$inject = ['$scope'];