Skip to content

Commit

Permalink
feat(ngTableColumnsBinding): new directive that provide access to the…
Browse files Browse the repository at this point in the history
… $columns array

This allows the $columns array to be accessed outside of the html table markup
  • Loading branch information
ccrowhurstram committed Sep 5, 2015
1 parent 7d2965c commit e290293
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module.exports = function(grunt) {
'src/scripts/ngTableController.js',
'src/scripts/ngTable.directive.js',
'src/scripts/ngTableDynamic.directive.js',
'src/scripts/ngTableColumnsBinding.directive.js',
'src/scripts/ngTablePagination.directive.js',
'src/scripts/ngTableFilterRowController.js',
'src/scripts/ngTableFilterRow.directive.js',
Expand Down
43 changes: 43 additions & 0 deletions src/scripts/ngTableColumnsBinding.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* ngTable: Table + Angular JS
*
* @author Vitalii Savchuk <[email protected]>
* @url https://github.com/esvit/ng-table/
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
*/

(function(){
'use strict';

angular.module('ngTable')
.directive('ngTableColumnsBinding', ngTableColumnsBinding);

ngTableColumnsBinding.$inject = ["$parse"];

/**
* @ngdoc service
* @name ngTableColumnsBinding
* @description One-way data binds the $columns array generated by ngTable/ngTableDynamic to the specified
* expression.
*
* This allows the $columns array to be accessed outside of the html table markup
*/
function ngTableColumnsBinding($parse){
var directive = {
restrict: 'A',
require: 'ngTable',
link: linkFn
};
return directive;

function linkFn($scope, $element, $attrs){
var setter = $parse($attrs.ngTableColumnsBinding).assign;
if (setter){
$scope.$watch('$columns', function(newColumns){
var shallowClone = (newColumns || []).slice(0);
setter($scope, shallowClone);
});
}
}
}
})();

0 comments on commit e290293

Please sign in to comment.