[Fixbug]行拖拽不能拖拽至第一行的问题

This commit is contained in:
yangchch6 2019-05-24 10:59:10 +08:00
parent 06a0d594fd
commit ccaf66777c
4 changed files with 46 additions and 16 deletions

View File

@ -205,17 +205,18 @@ var Table = function (_Component) {
targetIndex = i;
}
});
if (currentIndex < targetIndex) {
data.splice(targetIndex, 0, data.splice(currentIndex, 1).shift());
} else {
data.splice(targetIndex + 1, 0, data.splice(currentIndex, 1).shift());
}
data = _this.swapArray(data, currentIndex, targetIndex);
_this.props.onDropRow && _this.props.onDropRow(data, record);
_this.setState({
data: data
});
};
_this.swapArray = function (arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
};
_this.renderDragHideTable = function () {
var _this$props = _this.props,
columns = _this$props.columns,
@ -367,6 +368,10 @@ var Table = function (_Component) {
if (nextProps.resetScroll) {
this.resetScrollX();
}
// fix:模态框中使用table计算的滚动条宽度为0的bug
if (this.scrollbarWidth <= 0 && this.props.scroll.y) {
this.scrollbarWidth = (0, _utils.measureScrollbar)();
}
// console.log('this.scrollTop**********',this.scrollTop);
};
@ -733,6 +738,13 @@ var Table = function (_Component) {
* @param targetKey 拖拽结束时目标位置的key
*/
/**
* 数组元素交换位置
* @param {array} arr 数组
* @param {number} index1 添加项目的位置
* @param {number} index2 删除项目的位置
*/
/**
*

22
dist/demo.js vendored
View File

@ -34057,17 +34057,18 @@
targetIndex = i;
}
});
if (currentIndex < targetIndex) {
data.splice(targetIndex, 0, data.splice(currentIndex, 1).shift());
} else {
data.splice(targetIndex + 1, 0, data.splice(currentIndex, 1).shift());
}
data = _this.swapArray(data, currentIndex, targetIndex);
_this.props.onDropRow && _this.props.onDropRow(data, record);
_this.setState({
data: data
});
};
_this.swapArray = function (arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
};
_this.renderDragHideTable = function () {
var _this$props = _this.props,
columns = _this$props.columns,
@ -34219,6 +34220,10 @@
if (nextProps.resetScroll) {
this.resetScrollX();
}
// fix:模态框中使用table计算的滚动条宽度为0的bug
if (this.scrollbarWidth <= 0 && this.props.scroll.y) {
this.scrollbarWidth = (0, _utils.measureScrollbar)();
}
// console.log('this.scrollTop**********',this.scrollTop);
};
@ -34585,6 +34590,13 @@
* @param targetKey 拖拽结束时目标位置的key
*/
/**
* 数组元素交换位置
* @param {array} arr 数组
* @param {number} index1 添加项目的位置
* @param {number} index2 删除项目的位置
*/
/**
*

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -581,16 +581,22 @@ class Table extends Component {
targetIndex = i;
}
});
if(currentIndex < targetIndex){
data.splice(targetIndex, 0, data.splice(currentIndex, 1).shift());
}else{
data.splice((targetIndex+1), 0, data.splice(currentIndex, 1).shift());
}
data = this.swapArray(data,currentIndex,targetIndex);
this.props.onDropRow && this.props.onDropRow(data,record);
this.setState({
data,
});
}
/**
* 数组元素交换位置
* @param {array} arr 数组
* @param {number} index1 添加项目的位置
* @param {number} index2 删除项目的位置
*/
swapArray = (arr, index1, index2) => {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
}
/**
*