Add column reordering compatibility with RepeatCells configuration

This commit is contained in:
Aris Feryanto 2011-06-07 12:32:14 +07:00
parent e16b77c0a5
commit d64685c25a
3 changed files with 36 additions and 29 deletions

View File

@ -52,8 +52,10 @@
left: objPos.left
});
}
// get the column index
var n = $(this.t).find('th.draggable').index(obj);
// get the column index, zero-based
var n = this.getHeaderIdx(obj);
this.colMov = {
x0: e.pageX,
y0: e.pageY,
@ -89,7 +91,7 @@
// pointer animation
var hoveredCol = this.getHoveredCol(e);
if (hoveredCol) {
var newn = $(this.t).find('th.draggable').index(hoveredCol);
var newn = this.getHeaderIdx(hoveredCol);
this.colMov.newn = newn;
if (newn != this.colMov.n) {
// show the column pointer in the right place
@ -127,12 +129,9 @@
var n = this.colRsz.n;
// do the resizing
if (this.alignment != 'vertical') {
// resize the header
$(this.t).find('th.draggable:eq(' + n + ') span')
.css('width', nw);
// resize the data
$(this.t).find('tr:gt(0)').each(function() {
$(this).find('td:eq(' + (g.actionSpan + n) + ') span')
$(this.t).find('tr').each(function() {
$(this).find('th.draggable:eq(' + n + ') span,' +
'td:eq(' + (g.actionSpan + n) + ') span')
.css('width', nw);
});
} else { // vertical alignment
@ -176,7 +175,7 @@
reposRsz: function() {
$(this.cRsz).find('div').hide();
$firstRowCols = this.alignment != 'vertical' ?
$(this.t).find('th.draggable') :
$(this.t).find('tr:first th.draggable') :
$(this.t).find('tr:first td');
var firstElmtIdx = $firstRowCols.index();
$firstRowCols.each(function() {
@ -194,24 +193,17 @@
*/
shiftCol: function(oldn, newn) {
if (this.alignment != 'vertical') {
// shift header
$(this.t).find('thead tr').each(function() {
$(this.t).find('tr').each(function() {
if (newn < oldn) {
$(this).find('th.draggable:eq(' + newn + ')')
.before($(this).find('th.draggable:eq(' + oldn + ')'));
$(this).find('th.draggable:eq(' + newn + '),' +
'td:eq(' + (g.actionSpan + newn) + ')')
.before($(this).find('th.draggable:eq(' + oldn + '),' +
'td:eq(' + (g.actionSpan + oldn) + ')'));
} else {
$(this).find('th.draggable:eq(' + newn + ')')
.after($(this).find('th.draggable:eq(' + oldn + ')'));
}
});
// shift data
$(this.t).find('tbody tr').each(function() {
if (newn < oldn) {
$(this).find('td:eq(' + (g.actionSpan + newn) + ')')
.before($(this).find('td:eq(' + (g.actionSpan + oldn) + ')'));
} else {
$(this).find('td:eq(' + (g.actionSpan + newn) + ')')
.after($(this).find('td:eq(' + (g.actionSpan + oldn) + ')'));
$(this).find('th.draggable:eq(' + newn + '),' +
'td:eq(' + (g.actionSpan + newn) + ')')
.after($(this).find('th.draggable:eq(' + oldn + '),' +
'td:eq(' + (g.actionSpan + oldn) + ')'));
}
});
// reposition the column resize bars
@ -254,6 +246,21 @@
});
}
return hoveredCol;
},
/**
* Get a zero-based index from a <th class="draggable"> tag in a table.
*/
getHeaderIdx: function(obj) {
var n;
if (this.alignment != 'vertical') {
n = $(obj).parents('tr').find('th.draggable').index(obj);
} else {
var column_idx = $(obj).index();
var $th_in_same_column = $(this.t).find('th.draggable:nth-child(' + (column_idx + 1) + ')');
n = $th_in_same_column.index(obj);
}
return n;
}
}
@ -279,7 +286,7 @@
// get first row data columns
var $firstRowCols = g.alignment != 'vertical' ?
$(t).find('th.draggable') :
$(t).find('tr:first th.draggable') :
$(t).find('tr:first td');
// assign first column (actions) span

View File

@ -1881,7 +1881,7 @@ span.mysql-number {
width: 5px;
}
.pma_table thead th span, .pma_table tbody td span {
.pma_table th.draggable span, .pma_table tbody td span {
display: block;
overflow: hidden;
}

View File

@ -2215,7 +2215,7 @@ span.mysql-number {
width: 5px;
}
.pma_table thead th span, .pma_table tbody td span {
.pma_table th.draggable span, .pma_table tbody td span {
display: block;
overflow: hidden;
}