Skip to content

Commit

Permalink
feat(table-sortable): add optional additional classes to table
Browse files Browse the repository at this point in the history
[#80914122]

Signed-off-by: Bebe Peng <bpeng@pivotal.io>
  • Loading branch information
Nigel Pepper authored and stubbornella committed Dec 4, 2014
1 parent b83d9db commit ba154e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/pivotal-ui/components/tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ $(function() {
React.renderComponent(
TableSortable({
data: data,
columns: columns
columns: columns,
classes: ['table-data', 'table-light']
}),
document.getElementById('sortable-table-react-example')
);
Expand Down
5 changes: 4 additions & 1 deletion src/pivotal-ui/javascripts/table-sortable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ var TableSortable = module.exports = React.createClass({
);
}, this);

var defaultClasses = ['table', 'table-sortable'];
var allClasses = defaultClasses.concat(this.props.classes).join(' ');

return (
<table className='table table-data table-sortable'>
<table className={allClasses}>
<thead>
<tr>
{headings}
Expand Down
15 changes: 15 additions & 0 deletions test/spec/javascripts/table_sortable_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ describe('TableSortable', function() {
expect(this.$table.find('th:contains("Unsortable")')).not.toHaveClass('sortable');
});

it('adds the additional classes specified in the "classes" property', function() {
this.tableSortable = TableSortable({
data: this.data,
columns: this.columns,
classes: ['table-light']
});
React.renderComponent(this.tableSortable, this.node);
this.$table = $('#container table.table-sortable');

expect(this.$table).toHaveClass('table');
expect(this.$table).toHaveClass('table-sortable');

expect(this.$table).toHaveClass('table-light');
});

it('sorts table rows by the first column in ascending order by default', function() {
expect(this.$table.find('th:contains("Title")')).toHaveClass('sorted-asc');

Expand Down

0 comments on commit ba154e5

Please sign in to comment.