Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/tablesort.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

var sortOptions = [];

var createEvent = function(name) {
var createEvent = function(name, detail) {
var evt;

if (!window.CustomEvent || typeof window.CustomEvent !== 'function') {
if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { // IE
evt = document.createEvent('CustomEvent');
evt.initCustomEvent(name, false, false, undefined);
evt.initCustomEvent(name, /*canBubble:*/ false, /*cancelable:*/ false, detail);
} else {
evt = new CustomEvent(name);
evt = new CustomEvent(name, { detail: detail });
}

return evt;
Expand Down Expand Up @@ -144,7 +144,7 @@
sortMethod = header.getAttribute('data-sort-method'),
sortOrder = header.getAttribute('aria-sort');

that.table.dispatchEvent(createEvent('beforeSort'));
that.table.dispatchEvent(createEvent('beforeSort', { header: header, update: update }));

// If updating an existing sort, direction should remain unchanged.
if (!update) {
Expand All @@ -159,7 +159,10 @@
header.setAttribute('aria-sort', sortOrder);
}

if (that.table.rows.length < 2) return;
if( that.table.rows.length < 2 ) {
that.table.dispatchEvent(createEvent('sortCanceled', { header: header, update: update }));
return;
}

// If we force a sort method, it is not necessary to check rows
if (!sortMethod) {
Expand All @@ -183,7 +186,10 @@
i++;
}

if (!items) return;
if (!items) {
that.table.dispatchEvent(createEvent('sortCanceled', { header: header, update: update }));
return;
}
}

for (i = 0; i < sortOptions.length; i++) {
Expand Down Expand Up @@ -259,7 +265,7 @@
}
}

that.table.dispatchEvent(createEvent('afterSort'));
that.table.dispatchEvent(createEvent('afterSort', { header: header, update: update }));
},

refresh: function() {
Expand Down