Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sorting by clickin the entire header #2167

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/plugins/columnSorting/columnSorting.js
Expand Up @@ -274,6 +274,7 @@ function ColumnSorting() {
this.getColHeader = function(col, TH) {
if (this.getSettings().columnSorting && col >= 0) {
dom.addClass(TH.querySelector('.colHeader'), 'columnSorting');
dom.addClass(TH.querySelector('.colHeaderWrapper'), 'columnSorting');
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/tableView.js
Expand Up @@ -481,7 +481,7 @@ TableView.prototype.appendColHeader = function(col, TH) {
var DIV = document.createElement('DIV'),
SPAN = document.createElement('SPAN');

DIV.className = 'relative';
DIV.className = 'relative colHeaderWrapper';
SPAN.className = 'colHeader';

if (col > -1) {
Expand Down
17 changes: 17 additions & 0 deletions test/jasmine/spec/plugins/columnSortingSpec.js
Expand Up @@ -8,6 +8,10 @@ describe('ColumnSorting', function () {
// this.$container.find('th span.columnSorting:eq(' + columnIndex + ')').click();
this.$container.find('th span.columnSorting:eq(' + columnIndex + ')').simulate('click');
}

this.sortByHeaderWrapper = function(columnIndex) {
this.$container.find('th div.colHeaderWrapper:eq(' + columnIndex + ')').simulate('click');
}
});

afterEach(function () {
Expand Down Expand Up @@ -1100,4 +1104,17 @@ describe('ColumnSorting', function () {
expect(getDataAtCol(1)).toEqual(["Ted", "Sid", "Jane", "", "", null]);

});

it("should be sorted if the header outside the text is clicked", function() {
handsontable({
data: arrayOfObjects(),
colHeaders: true,
columnSorting: true
});

this.sortByHeaderWrapper(1);

expect(this.$container.find('tr td').eq(1).html()).toEqual('Chuck');
});

});