3 var ResizeColumns =
function ResizeColumns(table) {
5 this.startColumn =
false;
7 this.startWidth =
false;
9 this.prevHandle = null;
12 ResizeColumns.prototype.initializeColumn =
function (type, column, element) {
14 variableHeight =
false,
15 mode = this.table.options.resizableColumns;
18 if (type ===
"header") {
19 variableHeight = column.definition.formatter ==
"textarea" || column.definition.variableHeight;
20 column.modules.resize = { variableHeight: variableHeight };
23 if (mode ===
true || mode == type) {
25 var handle = document.createElement(
'div');
26 handle.className =
"tabulator-col-resize-handle";
28 var prevHandle = document.createElement(
'div');
29 prevHandle.className =
"tabulator-col-resize-handle prev";
31 handle.addEventListener(
"click",
function (e) {
35 var handleDown =
function handleDown(e) {
36 var nearestColumn = column.getLastColumn();
38 if (nearestColumn &&
self._checkResizability(nearestColumn)) {
39 self.startColumn = column;
40 self._mouseDown(e, nearestColumn, handle);
44 handle.addEventListener(
"mousedown", handleDown);
45 handle.addEventListener(
"touchstart", handleDown, { passive:
true });
48 handle.addEventListener(
"dblclick",
function (e) {
49 var col = column.getLastColumn();
51 if (col &&
self._checkResizability(col)) {
53 col.reinitializeWidth(
true);
57 prevHandle.addEventListener(
"click",
function (e) {
61 var prevHandleDown =
function prevHandleDown(e) {
62 var nearestColumn, colIndex, prevColumn;
64 nearestColumn = column.getFirstColumn();
67 colIndex =
self.table.columnManager.findColumnIndex(nearestColumn);
68 prevColumn = colIndex > 0 ?
self.table.columnManager.getColumnByIndex(colIndex - 1) :
false;
70 if (prevColumn &&
self._checkResizability(prevColumn)) {
71 self.startColumn = column;
72 self._mouseDown(e, prevColumn, prevHandle);
77 prevHandle.addEventListener(
"mousedown", prevHandleDown);
78 prevHandle.addEventListener(
"touchstart", prevHandleDown, { passive:
true });
81 prevHandle.addEventListener(
"dblclick",
function (e) {
82 var nearestColumn, colIndex, prevColumn;
84 nearestColumn = column.getFirstColumn();
87 colIndex =
self.table.columnManager.findColumnIndex(nearestColumn);
88 prevColumn = colIndex > 0 ?
self.table.columnManager.getColumnByIndex(colIndex - 1) :
false;
90 if (prevColumn &&
self._checkResizability(prevColumn)) {
92 prevColumn.reinitializeWidth(
true);
97 element.appendChild(handle);
98 element.appendChild(prevHandle);
102 ResizeColumns.prototype._checkResizability =
function (column) {
103 return typeof column.definition.resizable !=
"undefined" ? column.definition.resizable : this.table.options.resizableColumns;
106 ResizeColumns.prototype._mouseDown =
function (e, column, handle) {
109 self.table.element.classList.add(
"tabulator-block-select");
111 function mouseMove(e) {
114 column.setWidth(
self.startWidth + ((typeof e.screenX ===
"undefined" ? e.touches[0].screenX : e.screenX) -
self.startX));
116 if (!
self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight) {
117 column.checkCellHeights();
121 function mouseUp(e) {
124 if (
self.startColumn.modules.edit) {
125 self.startColumn.modules.edit.blocked =
false;
128 if (
self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight) {
129 column.checkCellHeights();
132 document.body.removeEventListener(
"mouseup", mouseUp);
133 document.body.removeEventListener(
"mousemove", mouseMove);
135 handle.removeEventListener(
"touchmove", mouseMove);
136 handle.removeEventListener(
"touchend", mouseUp);
138 self.table.element.classList.remove(
"tabulator-block-select");
140 if (
self.table.options.persistence &&
self.table.modExists(
"persistence",
true) &&
self.table.modules.persistence.config.columns) {
141 self.table.modules.persistence.save(
"columns");
144 self.table.options.columnResized.call(
self.table, column.getComponent());
150 if (
self.startColumn.modules.edit) {
151 self.startColumn.modules.edit.blocked =
true;
154 self.startX = typeof e.screenX ===
"undefined" ? e.touches[0].screenX : e.screenX;
155 self.startWidth = column.getWidth();
157 document.body.addEventListener(
"mousemove", mouseMove);
158 document.body.addEventListener(
"mouseup", mouseUp);
159 handle.addEventListener(
"touchmove", mouseMove, { passive:
true });
160 handle.addEventListener(
"touchend", mouseUp);
163 Tabulator.prototype.registerModule(
"resizeColumns", ResizeColumns);