Skip to content

Move Visible Rows & caption placeholder #39

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
41 changes: 25 additions & 16 deletions jquery.dragtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
beforeStart: $.noop, // returning FALSE will stop the execution chain.
beforeMoving: $.noop,
beforeReorganize: $.noop,
beforeStop: $.noop
beforeStop: $.noop,
zIndex: 10
},
originalTable: {
el: null,
Expand Down Expand Up @@ -115,7 +116,7 @@
},
// bubble the moved col left or right
_bubbleCols: function() {
var i, j, col1, col2;
var i, j, col1, col2, visibleRows;
var from = this.originalTable.startIndex;
var to = this.originalTable.endIndex;
/* Find children thead and tbody.
Expand All @@ -125,22 +126,23 @@
if (this.options.excludeFooter) {
thtb = thtb.not('tfoot');
}
row = thtb.find('> tr');
if (from < to) {
for (i = from; i < to; i++) {
col1 = thtb.find('> tr > td:nth-child(' + i + ')')
.add(thtb.find('> tr > th:nth-child(' + i + ')'));
col2 = thtb.find('> tr > td:nth-child(' + (i + 1) + ')')
.add(thtb.find('> tr > th:nth-child(' + (i + 1) + ')'));
col1 = row.find('> td:nth-child(' + i + ')')
.add(row.find('> th:nth-child(' + i + ')'));
col2 = row.find('> td:nth-child(' + (i + 1) + ')')
.add(row.find('> th:nth-child(' + (i + 1) + ')'));
for (j = 0; j < col1.length; j++) {
swapNodes(col1[j], col2[j]);
}
}
} else {
for (i = from; i > to; i--) {
col1 = thtb.find('> tr > td:nth-child(' + i + ')')
.add(thtb.find('> tr > th:nth-child(' + i + ')'));
col2 = thtb.find('> tr > td:nth-child(' + (i - 1) + ')')
.add(thtb.find('> tr > th:nth-child(' + (i - 1) + ')'));
col1 = row.find('> td:nth-child(' + i + ')')
.add(row.find('> th:nth-child(' + i + ')'));
col2 = row.find('> td:nth-child(' + (i - 1) + ')')
.add(row.find('> th:nth-child(' + (i - 1) + ')'));
for (j = 0; j < col1.length; j++) {
swapNodes(col1[j], col2[j]);
}
Expand Down Expand Up @@ -196,7 +198,7 @@
var rowAttrsArr = [];
//compute height, special handling for ie needed :-(
var heightArr = [];
this.originalTable.el.find('tr').slice(0, this.options.maxMovingRows).each(function(i, v) {
this.originalTable.el.find('tr:visible').slice(0, this.options.maxMovingRows).each(function(i, v) {
// row attributes
var attrs = this.attributes;
var attrsString = "";
Expand All @@ -220,7 +222,8 @@
if (this.options.excludeFooter) {
thtb = thtb.not('tfoot');
}
thtb.find('> tr > th').each(function(i, v) {
var visibleRows = thtb.find('> tr:visible');
visibleRows.find('> th').each(function(i, v) {
var w = $(this).outerWidth();
widthArr.push(w);
totalWidth += w;
Expand All @@ -232,15 +235,21 @@
// one extra px on right and left side
totalWidth += 2

var sortableHtml = '<ul class="dragtable-sortable" style="position:absolute; width:' + totalWidth + 'px;">';
var captionHeight = 0;
_this.originalTable.el.find('caption').each(function(){
captionHeight += $(this).outerHeight();
});

var sortableHtml = '<ul class="dragtable-sortable" style="position:absolute; width:' + totalWidth + 'px; z-index:' + _this.options.zIndex + '">';
// assemble the needed html
thtb.find('> tr > th').each(function(i, v) {
visibleRows.find('> th').each(function(i, v) {
var width_li = $(this).outerWidth();
sortableHtml += '<li style="width:' + width_li + 'px;">';
sortableHtml += '<table ' + attrsString + '>';
var row = thtb.find('> tr > th:nth-child(' + (i + 1) + ')');
sortableHtml += captionHeight ? '<caption style="height:' + captionHeight + 'px"></caption>' : '';
var row = visibleRows.find('> th:nth-child(' + (i + 1) + ')');
if (_this.options.maxMovingRows > 1) {
row = row.add(thtb.find('> tr > td:nth-child(' + (i + 1) + ')').slice(0, _this.options.maxMovingRows - 1));
row = row.add(visibleRows.find('> td:nth-child(' + (i + 1) + ')').slice(0, _this.options.maxMovingRows - 1));
}
row.each(function(j) {
// TODO: May cause duplicate style-Attribute
Expand Down