v1.6.1 拖拽bugfix

This commit is contained in:
“jonyshi” 2018-12-03 14:37:15 +08:00
parent b2b307f673
commit f9f4dcfdf5
3 changed files with 133 additions and 130 deletions

View File

@ -12,33 +12,18 @@ const propTypes = {
rows: PropTypes.array rows: PropTypes.array
}; };
const grap = 16; //偏移数值
class TableHeader extends Component { class TableHeader extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.currentObj = null; this.currentObj = null;
//拖拽宽度处理
if (!props.dragborder) return;
this.border = false;
this.theadKey = new Date().getTime(); this.theadKey = new Date().getTime();
this.drag = { this.drag = {
initPageLeftX: 0,
initLeft: 0,
x: 0,
width: 0,
option:'' option:''
}; };
this.minWidth = 80;//确定最小宽度就是80 this.minWidth = 80;//确定最小宽度就是80
this.table = null; this.table = null;
let _row = [];
this.props.rows[0] &&
this.props.rows[0].forEach(item => {
let newItem = item.key != "checkbox" ? ObjectAssign(item) : item;
_row.push(newItem);
});
this.drag.data = _row; //JSON.parse(JSON.stringify(this.props.rows[0]));
} }
static defaultProps = { static defaultProps = {
contentWidthDiff: 0 contentWidthDiff: 0
}; };
@ -53,8 +38,15 @@ class TableHeader extends Component {
for (let index = 0; index < ths.length; index++) { for (let index = 0; index < ths.length; index++) {
const element = ths[index];//.getAttribute('data-type'); const element = ths[index];//.getAttribute('data-type');
if(!element.getAttribute('data-th-fixed')){ if(!element.getAttribute('data-th-fixed')){
const colLine = element.children.length > 1?element.lastElementChild:element.children[0]; let colLine = null;
// const colLine = element.children[0]; if(element.children.length === 0){
colLine = element;
}else if(element.children.length > 0){
colLine = element.lastElementChild;
}else if(element.children.length === 1){
colLine = element.children[0];
}
// const colLine = element.children.length > 1?element.lastElementChild:element.children[0];
for (let i = 0; i < events.length; i++) { for (let i = 0; i < events.length; i++) {
const _event = events[i]; const _event = events[i];
let _dataSource = eventSource?element:colLine; let _dataSource = eventSource?element:colLine;

View File

@ -1,5 +1,6 @@
import React, { Component } from "react"; import React, { Component } from "react";
import {compare,ObjectAssign} from './util'; import {compare,ObjectAssign} from './util';
let cloneDeep = require('lodash.clonedeep');
/** /**
* 参数: 列拖拽 * 参数: 列拖拽
* @param {*} Table * @param {*} Table
@ -65,26 +66,36 @@ export default function dragColumn(Table) {
columns[index] = dragSourceColum; columns[index] = dragSourceColum;
} }
} }
let titles = []; // let titles = [];
columns.forEach(da=>{ // columns.forEach(da=>{
if(typeof da.title != "string"){ // for(let attr of da){
titles.push(da.title);
delete da.title; // }
} // if(typeof da.title != "string"){
}); // titles.push(da.title);
let newColumns = null; // delete da.title;
if(titles.length != 0){ // }
newColumns = JSON.parse(JSON.stringify(columns)); // });
for (let index = 0; index < newColumns.length; index++) { // let newColumns = null;
newColumns[index].title = titles[index]; // if(titles.length != 0){
} // newColumns = JSON.parse(JSON.stringify(columns));
console.log("----columns----",newColumns); // for (let index = 0; index < newColumns.length; index++) {
}else{ // newColumns[index].title = titles[index];
newColumns = JSON.parse(JSON.stringify(columns)); // }
} // console.log("----columns----",newColumns);
// }else{
// newColumns = JSON.parse(JSON.stringify(columns));
// }
// this.setState({
// columns:newColumns
// });
this.setState({ this.setState({
columns:newColumns columns:cloneDeep(columns)
}); });
if(this.props.dragDrop){
this.props.dragDrop(event,data,newColumns);
}
} }
getTarget=(evt)=>{ getTarget=(evt)=>{