bee-table/demo/demolist/Demo31.js

105 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-12-21 10:08:56 +08:00
/**
*
2019-03-20 17:44:05 +08:00
* @title hover呼出操作栏
* @description
2018-12-21 10:08:56 +08:00
*/
import React, { Component } from "react";
import {Tooltip,Button,Popconfirm} from "tinper-bee";
2018-12-21 10:08:56 +08:00
import Table from "../../src";
2019-03-20 17:44:05 +08:00
const columns = [
2018-12-21 10:08:56 +08:00
{
2019-03-20 17:44:05 +08:00
title: "用户名", dataIndex: "a", key: "a", width: 80, className: "rowClassName",
fixed:'left',
render: (text, record, index) => {
2018-12-21 10:08:56 +08:00
return (
2019-03-20 17:44:05 +08:00
<Tooltip inverse overlay={text}>
<span tootip={text} style={{
display: "inline-block",
width: "60px",
textOverflow: "ellipsis",
overflow: "hidden",
whiteSpace: "nowrap",
verticalAlign: "middle",
}}>{text}</span>
</Tooltip>
2018-12-21 10:08:56 +08:00
);
}
},
{ id: "123", title: "性别", dataIndex: "b", key: "b", width: 100 },
2019-03-20 17:44:05 +08:00
{ title: "年龄", dataIndex: "c", key: "c", width: 300 },
2018-12-21 10:08:56 +08:00
{
title: "操作",
dataIndex: "d",
key: "d",
render(text, record, index) {
return (
2019-03-20 17:44:05 +08:00
<div style={{ position: 'relative' }} title={text} >
<Popconfirm trigger="click" placement="right" content={'这是第' + index + '行,内容为:' + text}>
<a href="javascript:;" tooltip={text} >
一些操作
</a>
</Popconfirm>
2019-03-20 17:44:05 +08:00
</div>
2018-12-21 10:08:56 +08:00
);
}
2019-03-20 17:44:05 +08:00
}
2018-12-21 10:08:56 +08:00
];
2019-03-20 17:44:05 +08:00
const data = [
{ a: "令狐冲", b: "男", c: 41, d: "操作", key: "1" },
{ a: "杨过叔叔的女儿黄蓉", b: "男", c: 67, d: "操作", key: "2" },
{ a: "郭靖", b: "男", c: 25, d: "操作", key: "3" }
];
2019-02-21 19:44:00 +08:00
2019-03-20 17:44:05 +08:00
class Demo35 extends Component {
2019-02-21 19:44:00 +08:00
2019-03-20 17:44:05 +08:00
constructor(props) {
2018-12-21 10:08:56 +08:00
super(props);
2019-03-20 17:44:05 +08:00
this.state = {
data: data,
selectedRowIndex: 0
2018-12-21 10:08:56 +08:00
}
}
2019-03-20 17:44:05 +08:00
delFun=()=>{
// console.log('click'+this.currentIndex);
let {data} = this.state;
data.splice(this.currentIndex,1);
this.setState({
data
});
}
onRowHover=(index,record)=>{
this.currentIndex = index;
this.currentRecord = record;
}
getHoverContent=()=>{
return <div className="opt-btns"><Button size="sm" onClick={this.delFun}>删除</Button> </div>
2018-12-21 10:08:56 +08:00
}
render() {
return (
2019-03-20 17:44:05 +08:00
<Table
columns={columns}
data={data}
parentNodeId='parent'
height={40}
headerHeight={40}
2019-03-20 17:44:05 +08:00
hoverContent={this.getHoverContent}
onRowHover={this.onRowHover}
onRowClick={(record, index, indent) => {
this.setState({
selectedRowIndex: index
});
}}
/>
2018-12-21 10:08:56 +08:00
);
}
}
2019-03-20 17:44:05 +08:00
export default Demo35;