bindMoveColumn on every call of refreshHeader
This commit is contained in:
parent
f9775ecdf2
commit
f3a8b465ef
@ -30,15 +30,7 @@ export default class ColumnManager {
|
|||||||
|
|
||||||
refreshHeader() {
|
refreshHeader() {
|
||||||
const columns = this.datamanager.getColumns();
|
const columns = this.datamanager.getColumns();
|
||||||
const $cols = $.each('.dt-cell--header', this.header);
|
|
||||||
|
|
||||||
const refreshHTML =
|
|
||||||
// first init
|
|
||||||
!$('.dt-cell', this.header) ||
|
|
||||||
// deleted column
|
|
||||||
columns.length < $cols.length;
|
|
||||||
|
|
||||||
if (refreshHTML) {
|
|
||||||
// refresh html
|
// refresh html
|
||||||
$('thead', this.header).innerHTML = this.getHeaderHTML(columns);
|
$('thead', this.header).innerHTML = this.getHeaderHTML(columns);
|
||||||
|
|
||||||
@ -46,25 +38,9 @@ export default class ColumnManager {
|
|||||||
if (this.$filterRow) {
|
if (this.$filterRow) {
|
||||||
$.style(this.$filterRow, { display: 'none' });
|
$.style(this.$filterRow, { display: 'none' });
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// update data-attributes
|
|
||||||
$cols.map(($col, i) => {
|
|
||||||
const column = columns[i];
|
|
||||||
// column sorted or order changed
|
|
||||||
// update colIndex of each header cell
|
|
||||||
$.data($col, {
|
|
||||||
colIndex: column.colIndex
|
|
||||||
});
|
|
||||||
|
|
||||||
// refresh sort indicator
|
|
||||||
const sortIndicator = $('.sort-indicator', $col);
|
|
||||||
if (sortIndicator) {
|
|
||||||
sortIndicator.innerHTML = this.options.sortIndicator[column.sortOrder];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// reset columnMap
|
// reset columnMap
|
||||||
this.$columnMap = [];
|
this.$columnMap = [];
|
||||||
|
this.bindMoveColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeaderHTML(columns) {
|
getHeaderHTML(columns) {
|
||||||
@ -82,7 +58,6 @@ export default class ColumnManager {
|
|||||||
bindEvents() {
|
bindEvents() {
|
||||||
this.bindDropdown();
|
this.bindDropdown();
|
||||||
this.bindResizeColumn();
|
this.bindResizeColumn();
|
||||||
this.bindMoveColumn();
|
|
||||||
this.bindFilter();
|
this.bindFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,16 +158,6 @@ export default class ColumnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bindMoveColumn() {
|
bindMoveColumn() {
|
||||||
let initialized;
|
|
||||||
|
|
||||||
const initialize = () => {
|
|
||||||
if (initialized) {
|
|
||||||
$.off(document.body, 'mousemove', initialize);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const ready = $('.dt-cell', this.header);
|
|
||||||
if (!ready) return;
|
|
||||||
|
|
||||||
const $parent = $('.dt-row', this.header);
|
const $parent = $('.dt-row', this.header);
|
||||||
|
|
||||||
this.sortable = Sortable.create($parent, {
|
this.sortable = Sortable.create($parent, {
|
||||||
@ -214,9 +179,6 @@ export default class ColumnManager {
|
|||||||
chosenClass: 'dt-cell--dragging',
|
chosenClass: 'dt-cell--dragging',
|
||||||
animation: 150
|
animation: 150
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
$.on(document.body, 'mousemove', initialize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sortColumn(colIndex, nextSortOrder) {
|
sortColumn(colIndex, nextSortOrder) {
|
||||||
@ -325,11 +287,9 @@ export default class ColumnManager {
|
|||||||
|
|
||||||
setColumnWidth(colIndex, width) {
|
setColumnWidth(colIndex, width) {
|
||||||
colIndex = +colIndex;
|
colIndex = +colIndex;
|
||||||
this._columnWidthMap = this._columnWidthMap || [];
|
|
||||||
|
|
||||||
let columnWidth = width || this.getColumn(colIndex).width;
|
let columnWidth = width || this.getColumn(colIndex).width;
|
||||||
|
|
||||||
let index = this._columnWidthMap[colIndex];
|
|
||||||
const selector = [
|
const selector = [
|
||||||
`.dt-cell__content--col-${colIndex}`,
|
`.dt-cell__content--col-${colIndex}`,
|
||||||
`.dt-cell__edit--col-${colIndex}`
|
`.dt-cell__edit--col-${colIndex}`
|
||||||
@ -339,11 +299,7 @@ export default class ColumnManager {
|
|||||||
width: columnWidth + 'px'
|
width: columnWidth + 'px'
|
||||||
};
|
};
|
||||||
|
|
||||||
index = this.style.setStyle(selector, styles, index);
|
this.style.setStyle(selector, styles);
|
||||||
|
|
||||||
if (index !== undefined) {
|
|
||||||
this._columnWidthMap[colIndex] = index;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setColumnHeaderWidth(colIndex) {
|
setColumnHeaderWidth(colIndex) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user