Last active
August 7, 2016 04:06
-
-
Save alecklandgraf/0a625e4b64330c06ecb7b6bc180c76b8 to your computer and use it in GitHub Desktop.
statelessTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* usage: | |
* <stateless-table | |
* data="[{first_name: 'Aleck', last_name: 'Landgraf'}, ...]" | |
* on-header-click="sortData()" | |
* ></stateless-table> | |
*/ | |
module.component('statelessTable', { | |
bindings: { | |
data: '<', | |
onHeaderClick: '&' | |
}, | |
controller: () => { | |
var ctrl = this; | |
ctrl.$onInit = () => { | |
ctrl.columns = keys(ctrl.data[0]); | |
}; | |
}, | |
template: ` | |
<table> | |
<tr> | |
<th | |
ng-repeat="column in $ctrl.columns" | |
ng-click="$ctrl.onHeaderClick(column)" | |
>{{ column }}</th> | |
</tr> | |
<tr ng-repeat="row in $ctrl.data"> | |
<td ng-repeat="column in $ctrl.columns">{{ row[column] }}</td> | |
</tr> | |
</table> | |
`}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment