Skip to content

Commit

Permalink
feat(header): title and sortable expression now has access to the col…
Browse files Browse the repository at this point in the history
…umn definition

BREAKING CHANGE:

parse method on the ngTable scope has been removed as it's no longer required
  • Loading branch information
ccrowhurstram committed Jan 25, 2015
1 parent c2f83b9 commit 699b2a5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/ng-table/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<th title="{{column.headerTitle(this)}}"
ng-repeat="column in $columns"
ng-class="{
'sortable': parse(column.sortable),
'sort-asc': params.sorting()[parse(column.sortable)]=='asc',
'sort-desc': params.sorting()[parse(column.sortable)]=='desc'
'sortable': column.sortable(this),
'sort-asc': params.sorting()[column.sortable(this)]=='asc',
'sort-desc': params.sorting()[column.sortable(this)]=='desc'
}"
ng-click="sortBy(column, $event)"
ng-show="column.show(this)"
ng-init="template = column.headerTemplateURL(this)"
class="header {{column.class(this)}}">
<div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)"></div>
<div ng-if="!template" ng-show="!template" ng-bind="column.title(this)"></div>
<div ng-if="template" ng-show="template" ng-include="template"></div>
</th>
</tr>
<tr ng-show="show_filter" class="ng-table-filters">
<th data-title-text="{{parse(column.title)}}" ng-repeat="column in $columns" ng-show="column.show(this)" class="filter">
<th data-title-text="{{column.title(this)}}" ng-repeat="column in $columns" ng-show="column.show(this)" class="filter">
<div ng-repeat="(name, filter) in column.filter(this)">
<div ng-if="filter.indexOf('/') !== -1" ng-include="filter"></div>
<div ng-if="filter.indexOf('/') === -1" ng-include="'ng-table/filters/' + filter + '.html'"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/04-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ app.controller('ngTableController', ['$scope', 'NgTableParams', '$timeout', func
}, true);

$scope.sortBy = function(column, event) {
var parsedSortable = $scope.parse(column.sortable);
var parsedSortable = column.sortable && column.sortable($scope);
if (!parsedSortable) {
return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/scripts/05-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ app.directive('ngTable', ['$compile', '$q', '$parse',
scope.paramsModel = $parse(attrs.ngTable);
scope.params = params;
}), true);
scope.parse = function(text) {
return angular.isDefined(text) ? text(scope) : '';
};

if (attrs.showFilter) {
scope.$parent.$watch(attrs.showFilter, function(value) {
scope.show_filter = value;
Expand Down
23 changes: 23 additions & 0 deletions test/tableSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,29 @@ describe('ng-table', function() {
}));
});

describe('sorting', function() {

it('should provide column definition', inject(function($compile) {
var columnDef;
var elm = angular.element(
'<table ng-table="tableParams">' +
'<tr ng-repeat="user in $data">' +
'<td title="\'Age\'" sortable="captureColumn(column)">{{user.age}}</td>' +
'</tr>' +
'</table>');

scope.captureColumn = function(col){
columnDef = col;
return 'age'
};

$compile(elm)(scope);
scope.$digest();

expect(columnDef).toBeDefined();
}));
});

describe('filters', function(){

var columnDef;
Expand Down

0 comments on commit 699b2a5

Please sign in to comment.