Skip to content

Commit a6d1f6c

Browse files
author
黄书伟
committed
1、修复table组件单元格编辑后分页单元格内容不变化的问题 #24
2、废除单元格编辑格式化回调函数 `cell-edit-formatter`(破坏了响应式) 3、列宽拖动在IE9下失效的问题 #20
1 parent 6732326 commit a6d1f6c

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

packages/v-table/src/cell-edit-mixin.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,42 @@ export default {
1414
editInputLen,
1515
actionFun,
1616
textAlign,
17-
formatterVal = '';
17+
childTarget;
1818

1919
while ((target.className && target.className.indexOf('v-table-body-cell') === -1) || !target.className) {
2020
target = target.parentNode;
2121
}
2222

23+
// 子节点(span节点)
24+
childTarget = target.children[0];
25+
26+
// 把子节点影藏掉
27+
childTarget.style.display = 'none';
28+
2329
if (hasClass(target, 'cell-editing')) {
2430
return false
2531
}
2632

2733
addClass(target, 'cell-editing');
2834

29-
oldVal = target.innerText;
35+
oldVal = childTarget.innerText.trim();
3036

3137
if (target.style.textAlign) {
3238

3339
textAlign = target.style.textAlign;
3440
}
3541

36-
target.innerHTML = `<input type='text' value="${oldVal}" class='cell-edit-input' style='width:100%;height: 100%;text-align: ${textAlign};'>`;
42+
editInput = document.createElement('input');
43+
editInput.value = oldVal;
44+
editInput.className = 'cell-edit-input';
45+
editInput.style.textAlign = textAlign;
46+
editInput.style.width = '100%';
47+
editInput.style.height = '100%';
48+
//editInput.style = `width:100%;height: 100%;text-align: ${textAlign};`;
3749

38-
editInput = target.querySelector('.cell-edit-input');
39-
editInput.focus();
50+
target.appendChild(editInput);
4051

52+
editInput.focus();
4153

4254
editInputLen = editInput.value.length;
4355
if (document.selection) {
@@ -49,7 +61,6 @@ export default {
4961
editInput.selectionStart = editInput.selectionEnd = editInputLen;
5062
}
5163

52-
5364
actionFun = function (e) {
5465

5566
if (typeof e.keyCode === 'undefined' || e.keyCode === 0 || e.keyCode == 13) {
@@ -61,15 +72,15 @@ export default {
6172
return false;
6273
}
6374

64-
formatterVal = self.cellEditFormatter && self.cellEditFormatter(editInput.value, oldVal, rowIndex, rowData, field);
65-
66-
target.innerHTML = formatterVal && formatterVal.length > 0 ? formatterVal : editInput.value;
75+
childTarget.style.display = '';
6776

6877
// fixed this.value bug in IE9
69-
callback(editInput.value, oldVal)
78+
callback(editInput.value, oldVal);
7079

7180
utils.unbind(editInput, 'blur', actionFun);
7281
utils.unbind(editInput, 'keydown', actionFun);
82+
83+
target.removeChild(editInput);
7384
}
7485
};
7586

@@ -80,14 +91,13 @@ export default {
8091

8192
// 单元格点击
8293
cellEditClick(e, isEdit, rowData, field, rowIndex){
83-
8494
if (isEdit) {
8595

8696
let self = this;
8797
// 单元格内容变化后的回调
8898
let onCellEditCallBack = function (newValue, oldVal) {
8999

90-
self.cellEditDone(newValue, oldVal, rowIndex, rowData, field);
100+
self.cellEditDone && self.cellEditDone(newValue, oldVal, rowIndex, rowData, field);
91101
}
92102

93103
this.cellEdit(e, onCellEditCallBack, rowIndex, rowData, field)

packages/v-table/src/drag-width-mixin.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// 列宽度拖动
22
import utils from '../../src/utils/utils.js'
3+
import {hasClass, addClass, removeClass} from '../../src/utils/dom.js'
34
export default {
45

56
data(){
@@ -45,7 +46,7 @@ export default {
4546

4647
target = event.target;
4748

48-
while (target && ((target.className && target.className.indexOf('v-table-title-cell') === -1) || !target.className)) {
49+
while (target && ((target.className && !hasClass(target, 'v-table-title-cell')) || !target.className)) {
4950
target = target.parentNode;
5051
}
5152

@@ -152,16 +153,17 @@ export default {
152153
if (this.totalColumnsWidth < this.internalWidth) {
153154

154155
rightViewBody.style.overflowX = 'hidden';
156+
157+
removeClass(rightViewBody, 'v-table-rightview-special-border');
155158
rightViewBody.classList.remove('v-table-rightview-special-border');
156159

157-
//this.internalColumns[this.internalColumns.length - 1].width += this.internalWidth - this.totalColumnsWidth - 2;
158-
}else{
160+
} else {
159161

160162
rightViewBody.style.overflowX = 'scroll';
161163

162-
if (!this.hasFrozenColumn){
164+
if (!this.hasFrozenColumn) {
163165

164-
rightViewBody.classList.add('v-table-rightview-special-border');
166+
addClass(rightViewBody, 'v-table-rightview-special-border');
165167
}
166168
}
167169

packages/v-table/src/table.vue

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,6 @@
455455
rowMouseLeave: Function,
456456
// 单元格编辑完成回调
457457
cellEditDone: Function,
458-
// 单元格编辑格式化
459-
cellEditFormatter: Function,
460458
// 单元格合并
461459
cellMerge: Function,
462460
// select all
@@ -809,24 +807,29 @@
809807
this.initColumns();
810808
},
811809
812-
'tableData': function (newVal) {
810+
// deep watch
811+
'tableData': {
813812
814-
this.internalTableData = this.initInternalTableData(newVal);
813+
handler:function (newVal) {
815814
816-
this.updateCheckboxGroupModel();
815+
this.internalTableData = this.initInternalTableData(newVal);
817816
818-
this.tableEmpty();
817+
this.updateCheckboxGroupModel();
819818
820-
if (Array.isArray(newVal) && newVal.length > 0) {
819+
this.tableEmpty();
821820
822-
this.initView();
821+
if (Array.isArray(newVal) && newVal.length > 0) {
823822
824-
if (!this.hasBindScrollEvent) {
825-
this.scrollControl();
823+
this.initView();
824+
825+
if (!this.hasBindScrollEvent) {
826+
this.scrollControl();
827+
}
826828
}
827-
}
828829
829-
this.resize();
830+
this.resize();
831+
},
832+
deep: true
830833
}
831834
}
832835
}

0 commit comments

Comments
 (0)