our own table, sortable

This commit is contained in:
Gwenhael Le Moine 2014-10-27 15:20:20 +01:00
parent 7d5f893175
commit 8bfd5349da
3 changed files with 40 additions and 29 deletions

View file

@ -2,7 +2,6 @@ var app = angular.module( 'app', [ 'ui.router',
'nvd3ChartDirectives',
'angularMoment',
'chieffancypants.loadingBar',
'ngTable',
'angular-underscore',
'ngMaterial'
] );

View file

@ -56,17 +56,6 @@ app.controller( 'BalanceCtrl',
};
};
$scope.tableParams = new ngTableParams( {
page: 1, // show first page
count: 999 // count per page
}, {
counts: [], // hide page counts control
total: 1 //, // value less than count hide pagination
// getData: function($defer, params) {
// $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
// }
} );
$scope.filter_data = function() {
_($scope.balance.buckets).each( function( bucket ) {
bucket.data = [];
@ -91,11 +80,24 @@ app.controller( 'BalanceCtrl',
} );
}};
var Bucket = function( categories ) {
var _this = this;
this.categories = categories;
this.score_threshold = 0;
this.orderBy = 'amount';
this.orderDesc = false;
this.order_by = function( field ) {
if ( _this.orderBy == field ) {
_this.orderDesc = !_this.orderDesc;
} else {
_this.orderBy = field;
}
};
};
$scope.balance = {
buckets: [ { categories: 'Expenses',
score_threshold: 0 },
{ categories: 'Income',
score_threshold: 0 } ],
buckets: [ new Bucket( 'Expenses' ),
new Bucket( 'Income' ) ],
details: {}
};

View file

@ -55,19 +55,29 @@
</nvd3-pie-chart>
</material-content>
<material-content>
<table data-ng-table="tableParams" class="table">
<tr data-ng-repeat="account in bucket.data"
data-ng-class="{'even': $even, 'odd': $odd}"
style="border-left:10px solid {{coloring_score( account.score )}};border-right:10px solid {{coloring_score( account.score )}}">
<td data-title="'Account'"
style="border-bottom:1px solid {{coloring_score( score_account( account.account ) )}}">
{{account.account}}
</td>
<td data-title="'Amount'"
style="text-align:right;border-bottom:1px solid {{coloring_score( score_account( account.account ) )}}">
{{account.amount | number:2}} €
</td>
</tr>
<table class="table">
<thead>
<tr>
<th><material-buton data-ng-click="bucket.order_by( 'account' )">account</material-buton></th>
<th><material-buton data-ng-click="bucket.order_by( 'amount' )">amount</material-buton></th>
<th><material-buton data-ng-click="bucket.order_by( 'score' )">score</material-buton></th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="account in bucket.data | orderBy:bucket.orderBy:bucket.orderDesc"
data-ng-class="{'even': $even, 'odd': $odd}"
style="border-left:10px solid {{coloring_score( account.score )}};border-right:10px solid {{coloring_score( account.score )}}">
<td style="border-bottom:1px solid {{coloring_score( account.score )}}">
{{account.account}}
</td>
<td style="text-align:right;border-bottom:1px solid {{coloring_score( account.score )}}">
{{account.amount | number:2}} €
</td>
<td style="text-align:right;border-bottom:1px solid {{coloring_score( account.score )}}">
{{account.score}}
</td>
</tr>
</tbody>
</table>
</material-content>
</div>