Skip to content

Commit

Permalink
feat(ngTable): add title-alt for displaying an alternative header tit…
Browse files Browse the repository at this point in the history
…le for responsive tables
  • Loading branch information
ccrowhurstram committed Feb 10, 2015
1 parent 88f8a40 commit afc1423
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/demo32.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ <h1>Responsive table</h1>

<table ng-table="tableParams" show-filter="true" class="table table-bordered table-striped">
<tr ng-repeat="user in $data">
<td data-title="'Name'" sortable="'name'" filter="{ 'name': 'text' }">
<td title="'Full Name'" title-alt="'Name'" sortable="'name'" filter="{ 'name': 'text' }">
{{user.name}}
</td>
<td data-title="'Age'" sortable="'age'" filter="{ 'age': 'text' }">
<td title="'Age'" sortable="'age'" filter="{ 'age': 'text' }">
{{user.age}}
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion src/ng-table/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</th>
</tr>
<tr ng-show="show_filter" class="ng-table-filters">
<th data-title-text="{{column.title(this)}}" ng-repeat="column in $columns" ng-show="column.show(this)" class="filter">
<th data-title-text="{{column.titleAlt(this) || 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
3 changes: 2 additions & 1 deletion src/scripts/04-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ app.factory('ngTableColumn', [function () {
headerTitle: function(){ return ' '; },
sortable: function(){ return false; },
show: function(){ return true; },
title: function(){ return ' '; }
title: function(){ return ' '; },
titleAlt: function(){ return ''; }
};

function buildColumn(column){
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/05-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ app.directive('ngTable', ['$q', '$parse',
};
};

var titleExpr = getAttrValue('title');
var titleExpr = getAttrValue('title-alt') || getAttrValue('title');
if (titleExpr){
el.attr('data-title-text', '{{' + titleExpr + '}}'); // this used in responsive table
}
Expand All @@ -69,6 +69,7 @@ app.directive('ngTable', ['$q', '$parse',
columns.push({
id: i++,
title: parsedAttribute('title'),
titleAlt: parsedAttribute('title-alt'),
headerTitle: parsedAttribute('header-title'),
sortable: parsedAttribute('sortable'),
'class': parsedAttribute('header-class'),
Expand Down
45 changes: 45 additions & 0 deletions test/tableSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,51 @@ describe('ng-table', function() {
}));
});

describe('title-alt', function() {

var elm;
beforeEach(inject(function($compile, NgTableParams) {
elm = angular.element(
'<table ng-table="tableParams">' +
'<tr ng-repeat="user in $data">' +
'<td title="\'Name of person\'" title-alt="\'Name\'">{{user.name}}</td>' +
'<td title="\'Age of person\'" data-title-alt="\'Age\'">{{user.age}}</td>' +
'<td title="\'Money earned\'" x-data-title-alt="\'£\'">{{user.money}}</td>' +
'</tr>' +
'</table>');

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

var params = new NgTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: data.length, // length of data
getData: function($defer, params) {
$defer.resolve(data);
}
});
scope.tableParams = params;
scope.$digest();
}));

it('should show as data-title-text', inject(function($compile) {
var filterRow = angular.element(elm.find('thead').find('tr')[1]);
var filterCells = filterRow.find('th');

expect(angular.element(filterCells[0]).attr('data-title-text').trim()).toBe('Name');
expect(angular.element(filterCells[1]).attr('data-title-text').trim()).toBe('Age');
expect(angular.element(filterCells[2]).attr('data-title-text').trim()).toBe('£');

var dataRows = elm.find('tbody').find('tr');
var dataCells = angular.element(dataRows[0]).find('td');
expect(angular.element(dataCells[0]).attr('data-title-text').trim()).toBe('Name');
expect(angular.element(dataCells[1]).attr('data-title-text').trim()).toBe('Age');
expect(angular.element(dataCells[2]).attr('data-title-text').trim()).toBe('£');
}));
});

describe('sorting', function() {

it('should provide column definition', inject(function($compile) {
Expand Down

0 comments on commit afc1423

Please sign in to comment.