diff --git a/Scripts/bootstrap-sortable.js b/Scripts/bootstrap-sortable.js
index 0560bba..1557228 100644
--- a/Scripts/bootstrap-sortable.js
+++ b/Scripts/bootstrap-sortable.js
@@ -68,7 +68,7 @@
$this.find('span.sign').remove();
// Add placeholder cells for colspans
- $this.find('thead [colspan]').each(function () {
+ $this.find('> thead [colspan]').each(function () {
var colspan = parseFloat($(this).attr('colspan'));
for (var i = 1; i < colspan; i++) {
$(this).after('
');
@@ -76,7 +76,7 @@
});
// Add placeholder cells for rowspans
- $this.find('thead [rowspan]').each(function () {
+ $this.find('> thead [rowspan]').each(function () {
var $cell = $(this);
var rowspan = parseFloat($cell.attr('rowspan'));
for (var i = 1; i < rowspan; i++) {
@@ -88,7 +88,7 @@
});
// Set indexes to header cells
- $this.find('thead tr').each(function (rowIndex) {
+ $this.find('> thead tr').each(function (rowIndex) {
$(this).find('th').each(function (columnIndex) {
var $header = $(this);
$header.addClass('nosort').removeClass('up down');
@@ -98,7 +98,7 @@
});
// Cleanup placeholder cells
- $this.find('thead .rowspan-compensate, .colspan-compensate').remove();
+ $this.find('> thead .rowspan-compensate, .colspan-compensate').remove();
// Initialize sorting values specified in header
$this.find('th').each(function () {
@@ -136,7 +136,7 @@
var context = lookupSortContext($this),
bsSort = context.bsSort;
- $this.find('thead th[data-defaultsort!="disabled"]').each(function (index) {
+ $this.find('> thead th[data-defaultsort!="disabled"]').each(function (index) {
var $header = $(this);
var $sortTable = $header.closest('table.sortable');
$header.data('sortTable', $sortTable);
@@ -168,7 +168,7 @@
var context = $table.data("bootstrap-sortable-context");
if (context === undefined) {
context = { bsSort: [], lastSort: undefined };
- $table.find('thead th[data-defaultsort!="disabled"]').each(function (index) {
+ $table.find('> thead th[data-defaultsort!="disabled"]').each(function (index) {
var $this = $(this);
var sortKey = $this.attr('data-sortkey');
context.bsSort[sortKey] = $this.attr('data-defaultsort');
@@ -199,7 +199,7 @@
var rowIndex = parseFloat($this.data('sortkey').split('-').pop());
// If there is one more row in header, delve deeper
- if ($table.find('thead tr').length - 1 > rowIndex) {
+ if ($table.find('> thead tr').length - 1 > rowIndex) {
doSort($table.find('[data-sortkey="' + (sortColumn + mainSort) + '-' + (rowIndex + 1) + '"]'), $table);
return;
}
@@ -210,12 +210,12 @@
var localSignClass = $this.attr('data-defaultsign') || signClass;
// update arrow icon
- $table.find('th').each(function () {
+ $table.find('> thead th').each(function () {
$(this).removeClass('up').removeClass('down').addClass('nosort');
});
if ($.browser.mozilla) {
- var moz_arrow = $table.find('div.mozilla');
+ var moz_arrow = $table.find('> thead div.mozilla');
if (moz_arrow !== undefined) {
moz_arrow.find('.sign').remove();
moz_arrow.parent().html(moz_arrow.html());
@@ -224,7 +224,7 @@
$this.children().eq(0).append('');
}
else {
- $table.find('span.sign').remove();
+ $table.find('> thead span.sign').remove();
$this.append('');
}
@@ -272,7 +272,7 @@
});
// add class to sorted column cells
- $table.find('td.sorted, th.sorted').removeClass('sorted');
+ $table.find('> tbody > tr > td.sorted,> thead th.sorted').removeClass('sorted');
rowsToSort.find('td:eq(' + sortColumn + ')').addClass('sorted');
$this.addClass('sorted');
$table.trigger('sorted');
diff --git a/Tests/tableInsideTable.html b/Tests/tableInsideTable.html
new file mode 100644
index 0000000..956d7a8
--- /dev/null
+++ b/Tests/tableInsideTable.html
@@ -0,0 +1,72 @@
+
+
+
+ Bootstrap Sortable Tables
+
+
+
+
+
+ head1 |
+ head2 |
+ head3 |
+ head4 |
+
+
+
+
+ 2 |
+ hi |
+ 2015/04/08 |
+ 5.234 |
+
+
+ 5 |
+ yeah |
+ 2013/03/16 |
+ 548.2154 |
+
+
+ 1 |
+ test |
+ 2005/10/24 |
+ 1.547 |
+
+
+
+
+
+
+ head1 |
+ head2 |
+ head3 |
+ head4 |
+
+
+
+
+ 2 |
+ hi |
+ 2015/04/08 |
+ 5.234 |
+
+
+ 5 |
+ yeah |
+ 2013/03/16 |
+ 548.2154 |
+
+
+ 1 |
+ test |
+ 2005/10/24 |
+ 1.547 |
+
+
+
+ |
+
+
+
+
+
diff --git a/Tests/tableInsideTable.js b/Tests/tableInsideTable.js
new file mode 100644
index 0000000..1e035c4
--- /dev/null
+++ b/Tests/tableInsideTable.js
@@ -0,0 +1,34 @@
+jasmine.getFixtures().fixturesPath = 'base/Tests/';
+
+describe('Table inside table sorting', function() {
+ beforeEach(function() {
+ jasmine.getFixtures().load('tableInsideTable.html');
+ $.bootstrapSortable();
+ });
+
+ it("Outer table has correct order of rows", function() {
+ var index = $('#outerFirst').index('#outer > tr');
+ expect(index).toBe(1);
+ });
+
+ it("Inner table has correct order of rows", function() {
+ var index = $('#innerFirst').index('#inner > tr');
+ expect(index).toBe(0);
+ });
+
+ it("Inner table header keeps sorted class after outer sorting", function() {
+ var innerHeader = $('#innerh1');
+ expect(innerHeader.hasClass('sorted')).toBe(true);
+
+ $.bootstrapSortable({ sortingHeader: $('#outerh2') });
+ expect(innerHeader.hasClass('sorted')).toBe(true);
+ });
+
+ it("Inner table header keeps sorted icon after outer sorting", function() {
+ var innerHeader = $('#innerh1');
+ expect(innerHeader.children('.sign').length).toBe(1);
+
+ $.bootstrapSortable({ sortingHeader: $('#outerh2') });
+ expect(innerHeader.children('.sign').length).toBe(1);
+ });
+});
|