2019-04-25 13:53:39 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @title 拖拽改变行顺序
|
2019-04-25 16:09:48 +08:00
|
|
|
|
* @parent 行操作-拖拽
|
2020-07-13 21:14:33 +08:00
|
|
|
|
* @description `rowDraggAble`参数设置是否使用行交换顺序功能,`useDragHandle`设置拖拽把手,`onDropRow` 是拖拽行后的回调函数。注意:表格行数据必须有唯一标识,可以通过 `data.key` 或 `rowKey` 两种方式传入。
|
2019-04-25 13:53:39 +08:00
|
|
|
|
* Demo1201
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import Table from "../../src";
|
2019-08-07 10:32:05 +08:00
|
|
|
|
import Switch from 'bee-switch';
|
2019-04-25 13:53:39 +08:00
|
|
|
|
|
|
|
|
|
const columns = [
|
2019-04-28 15:02:03 +08:00
|
|
|
|
{ title: "员工编号", dataIndex: "a", key: "a", width: 150 },
|
2019-04-25 13:53:39 +08:00
|
|
|
|
{ title: "员工姓名", dataIndex: "b", key: "b", width:200 },
|
2019-08-07 10:32:05 +08:00
|
|
|
|
{ title: "系统权限", dataIndex: "c", key: "c", width: 200,render:()=>{return(<Switch size="sm" />)}},
|
2019-04-25 13:53:39 +08:00
|
|
|
|
{ title: "部门", dataIndex: "d", key: "d", width: 100 },
|
2019-04-28 15:02:03 +08:00
|
|
|
|
{ title: "职级", dataIndex: "e", key: "e", width: 100 }
|
2019-04-25 13:53:39 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const data = [
|
|
|
|
|
{ a: "ASVAL_201903280005", b: "小张", c: "男", d: "财务二科", e: "M1", key: "1001" },
|
|
|
|
|
{ a: "ASVAL_201903200004", b: "小明", c: "男", d: "财务一科", e: "T1", key: "1002" },
|
2019-04-26 17:54:54 +08:00
|
|
|
|
{ a: "ASVAL_201903120001", b: "小红", c: "女", d: "财务四科", e: "T3", key: "1003" },
|
|
|
|
|
{ a: "ASVAL_201903120002", b: "小姚", c: "女", d: "财务一科", e: "T2", key: "1004" },
|
2019-04-26 18:02:48 +08:00
|
|
|
|
{ a: "ASVAL_201903120003", b: "小岳", c: "男", d: "财务五科", e: "T2", key: "1005" },
|
|
|
|
|
{ a: "ASVAL_201903120004", b: "小王", c: "男", d: "财务一科", e: "T5", key: "1006" },
|
|
|
|
|
{ a: "ASVAL_201903120005", b: "小绍", c: "男", d: "财务七科", e: "T2", key: "1007" },
|
|
|
|
|
{ a: "ASVAL_201903120006", b: "小郭", c: "男", d: "财务一科", e: "T3", key: "1008" },
|
|
|
|
|
{ a: "ASVAL_201903120007", b: "小杨", c: "女", d: "财务四科", e: "T2", key: "1009" }
|
2019-04-25 13:53:39 +08:00
|
|
|
|
];
|
|
|
|
|
|
2020-07-14 16:43:10 +08:00
|
|
|
|
class Demo38 extends Component {
|
2019-04-25 13:53:39 +08:00
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
data: data
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
handleClick = () => {
|
|
|
|
|
console.log('这是第' , this.currentIndex , '行');
|
|
|
|
|
console.log('内容:' , this.currentRecord);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-16 11:30:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* 行拖拽开始时触发
|
|
|
|
|
* @param record 拖拽行的数据
|
|
|
|
|
* @param index 拖拽行的下标序号
|
|
|
|
|
*/
|
|
|
|
|
onDragRowStart = (record,index) => {
|
|
|
|
|
console.log('拖拽的行数据:', record);
|
|
|
|
|
console.log('拖拽的行序号:', index);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 18:20:13 +08:00
|
|
|
|
/**
|
|
|
|
|
* 行拖拽结束时触发
|
|
|
|
|
* @param data 拖拽改变顺序后的新data数组
|
|
|
|
|
* @param record 拖拽行的数据
|
|
|
|
|
*/
|
|
|
|
|
onDropRow = (data, record) => {
|
|
|
|
|
console.log('重排序后的data: ', data);
|
|
|
|
|
console.log('拖拽的行数据: ', record);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-25 13:53:39 +08:00
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<Table
|
|
|
|
|
columns={columns}
|
|
|
|
|
data={data}
|
|
|
|
|
rowDraggAble={true}
|
2020-07-16 09:57:18 +08:00
|
|
|
|
// useDragHandle={true}
|
2019-07-16 11:30:02 +08:00
|
|
|
|
onDragRowStart={this.onDragRowStart}
|
2019-05-22 18:20:13 +08:00
|
|
|
|
onDropRow={this.onDropRow}
|
2019-04-25 13:53:39 +08:00
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 16:43:10 +08:00
|
|
|
|
export default Demo38;
|