Last active
August 29, 2015 14:12
-
-
Save meatballs/94d7839275461185f5c4 to your computer and use it in GitHub Desktop.
PivotTable with AngularJS Directive and CoffeeScript
This file contains hidden or 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
'use strict' | |
app = angular.module('app') | |
class PivotCtrl | |
@$inject = [ | |
'$scope' | |
'pivotService' | |
] | |
constructor: ($scope, pivotService) -> | |
@pivotService = pivotService | |
app.controller 'PivotCtrl', PivotCtrl |
This file contains hidden or 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
'use strict' | |
app = angular.module('app') | |
app.directive 'pivotTable', -> | |
scope: { datasource: '=' }, | |
link: (scope, element, attrs) -> | |
scope.datasource.$promise.then (result) -> | |
$(element).pivotUI( | |
result, | |
scope.$eval(attrs.pivotTable)) |
This file contains hidden or 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
How to use pivottable with an AngularJS directive in coffeescript |
This file contains hidden or 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
'use strict' | |
app = angular.module('app') | |
class PivotService | |
@$inject = ['$resource'] | |
constructor: ($resource) -> | |
url = 'http:// whatever the rest of the url might be' | |
resource = $resource url, null, {query: {timeout: 5000, isArray: true}} | |
@pivotData = resource.query( | |
(data) -> | |
# do something here on success if necessary | |
return | |
(response) => | |
# do something here on failure if necessary | |
) | |
app.service 'pivotService', PivotService |
This file contains hidden or 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
<section ng-controller="PivotCtrl as ctrl"> | |
<div class="panel panel-default"> | |
<div datasource="ctrl.pivotService.pivotData" pivot-table="{rows: [], cols: [], vals: [], rendererName: 'Table'}"></div> | |
</div> | |
</section> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment