mirror of
https://github.com/liubinfighter/csv-lite.git
synced 2026-07-22 12:20:28 +00:00
feat: 为列号和行号单元格添加拖拽事件处理逻辑,增强用户交互体验 [FR] Drag to resize columns #20
This commit is contained in:
parent
8464338565
commit
f197973c01
2 changed files with 20 additions and 0 deletions
15
src/view.ts
15
src/view.ts
|
|
@ -355,6 +355,21 @@ export class CSVView extends TextFileView {
|
|||
onMoveColLeft: (colIdx) => this.moveCol(colIdx, colIdx - 1),
|
||||
onMoveColRight: (colIdx) => this.moveCol(colIdx, colIdx + 1),
|
||||
});
|
||||
|
||||
// 在 refresh 方法中调用 setupColumnResize,为列号和行号单元格绑定拖拽事件
|
||||
this.tableData[0].forEach((_, index) => {
|
||||
const resizeHandle = this.tableEl.querySelector(`.resize-handle[data-index='${index}']`) as HTMLElement;
|
||||
if (resizeHandle) {
|
||||
this.setupColumnResize(resizeHandle, index);
|
||||
}
|
||||
});
|
||||
|
||||
this.tableData.forEach((_, rowIndex) => {
|
||||
const resizeHandleRow = this.tableEl.querySelector(`.resize-handle-row[data-row-index='${rowIndex}']`) as HTMLElement;
|
||||
if (resizeHandleRow) {
|
||||
this.setupColumnResize(resizeHandleRow, rowIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 新增:获取列标签(A, B, C, ... Z, AA, AB, ...)
|
||||
|
|
|
|||
|
|
@ -154,6 +154,10 @@ export function renderTable(options: TableRenderOptions) {
|
|||
th.classList.add('csv-dragging-highlight');
|
||||
}
|
||||
}
|
||||
|
||||
// 在列号单元格中添加拖拽事件处理逻辑
|
||||
const resizeHandle = th.createEl("div", { cls: "resize-handle" });
|
||||
setupColumnResize(resizeHandle, index);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -184,6 +188,7 @@ export function renderTable(options: TableRenderOptions) {
|
|||
headerInput.onfocus = (ev) => {
|
||||
setActiveCell(0, index, ev.currentTarget as HTMLInputElement);
|
||||
};
|
||||
// 在列号单元格中添加拖拽事件处理逻辑
|
||||
const resizeHandle = th.createEl("div", { cls: "resize-handle" });
|
||||
setupColumnResize(resizeHandle, index);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue