|
@@ -535,6 +535,26 @@ const SpreadJsObj = {
|
|
cell.setBorder(sheet.borderLine, {all: true});
|
|
cell.setBorder(sheet.borderLine, {all: true});
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+ _autoFitRowWithTree: function(sheet, data, row, treeCol) {
|
|
|
|
+ const treeCell = sheet.getCell(row, treeCol);
|
|
|
|
+ const setting = sheet.zh_tree.setting;
|
|
|
|
+ const xOffset = 2 + 5;
|
|
|
|
+ const indent = 20;
|
|
|
|
+ const levelIndent = -5;
|
|
|
|
+ const move = (data[setting.level]) * indent + (data[setting.level]) * levelIndent + xOffset;
|
|
|
|
+ const validWidth = sheet.zh_setting.cols[treeCol].width - move;
|
|
|
|
+ const getTextHeight = function(sheet, str, font, width) {
|
|
|
|
+ const xs = sheet.getParent().xs;
|
|
|
|
+ const ctx = xs.childNodes[0].getContext("2d");
|
|
|
|
+ ctx.font = font;
|
|
|
|
+ const textMertrices = ctx.measureText(str);
|
|
|
|
+ const fontHeight = textMertrices.fontBoundingBoxAscent + textMertrices.fontBoundingBoxDescent;
|
|
|
|
+ const textRow = Math.ceil(textMertrices.width / width);
|
|
|
|
+ return textRow * fontHeight + 2 + (textRow - 1) * 1;
|
|
|
|
+ };
|
|
|
|
+ const treeCellHeight = getTextHeight(sheet, treeCell.text(), treeCell.font(), validWidth);
|
|
|
|
+ sheet.setRowHeight(row, Math.max(treeCellHeight, sheet.getRowHeight(row)));
|
|
|
|
+ },
|
|
_loadRowData: function (sheet, data, row) {
|
|
_loadRowData: function (sheet, data, row) {
|
|
// 单元格重新写入数据
|
|
// 单元格重新写入数据
|
|
if (!data) { return }
|
|
if (!data) { return }
|
|
@@ -542,8 +562,9 @@ const SpreadJsObj = {
|
|
data.waitingLoading = true;
|
|
data.waitingLoading = true;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- let autoFit = false;
|
|
|
|
|
|
+ let autoFit = false, treeWordWrapCol = -1;
|
|
sheet.zh_setting.cols.forEach(function (col, j) {
|
|
sheet.zh_setting.cols.forEach(function (col, j) {
|
|
|
|
+ if (col.cellType === 'tree' && col.wordWrap) treeWordWrapCol = j;
|
|
const cell = sheet.getCell(row, j);
|
|
const cell = sheet.getCell(row, j);
|
|
if (col.getValue && Object.prototype.toString.apply(col.getValue) === "[object Function]") {
|
|
if (col.getValue && Object.prototype.toString.apply(col.getValue) === "[object Function]") {
|
|
cell.value(col.getValue(data, col));
|
|
cell.value(col.getValue(data, col));
|
|
@@ -595,7 +616,10 @@ const SpreadJsObj = {
|
|
}
|
|
}
|
|
data.waitingLoading = false;
|
|
data.waitingLoading = false;
|
|
});
|
|
});
|
|
- if (autoFit) sheet.autoFitRow(row);
|
|
|
|
|
|
+ if (autoFit) {
|
|
|
|
+ sheet.autoFitRow(row);
|
|
|
|
+ if (treeWordWrapCol >= 0) this._autoFitRowWithTree(sheet, data, row, treeWordWrapCol);
|
|
|
|
+ }
|
|
},
|
|
},
|
|
_addActivePaintEvents: function (sheet, cellType) {
|
|
_addActivePaintEvents: function (sheet, cellType) {
|
|
if (!sheet.ActiveType) {
|
|
if (!sheet.ActiveType) {
|