bee-table/demo/demolist/Demo1.js

93 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-12-26 16:52:39 +08:00
/**
*
2018-04-26 15:11:32 +08:00
* @title 简单表格以及两种tip
* 一种是bee-popover实现
* 一种是标签本身的tooltip
2017-01-11 17:01:50 +08:00
* @description
2016-12-26 16:52:39 +08:00
*/
2016-12-26 22:04:16 +08:00
2017-10-25 16:41:38 +08:00
import React, { Component } from "react";
2018-04-26 15:11:32 +08:00
import Popover from 'bee-popover';
import Button from "bee-button";
2017-10-25 16:41:38 +08:00
import Table from "../../src";
2017-09-08 15:07:55 +08:00
2018-04-26 15:11:32 +08:00
function getTitleTip(text){
return(<div>
<h3>{text}</h3>
</div>)
}
2017-01-11 17:01:50 +08:00
const columns = [
2017-10-25 16:41:38 +08:00
{ id: "123", title: "性别", dataIndex: "b", key: "b", width: 100 },
{ title: "年龄", dataIndex: "c", key: "c", width: 200 },
2018-04-26 15:11:32 +08:00
{ title: "用户名", dataIndex: "a", key: "a", width:80 ,
render(text, record, index) {
return(<div style={{position: 'relative'}}>
<Popover
placement="leftTop"
content={getTitleTip(text)}
trigger="hover"
id="leftTop"
>
<span
style={{
position: 'absolute',
top: 5,
left: 0,
width: "80px",
textOverflow:"ellipsis",
overflow:"hidden",
whiteSpace:"nowrap"
}}>{text}</span>
</Popover>
</div>);
}},
2017-01-11 17:01:50 +08:00
{
2017-10-25 16:41:38 +08:00
title: "操作",
dataIndex: "d",
key: "d",
render(text, record, index) {
return (
2018-04-26 15:11:32 +08:00
<div style={{position: 'relative'}} title={text} >
<a
href="#"
tooltip={text}
onClick={() => {
alert('这是第'+index+'列,内容为:'+text);
}}
style={{
position: 'absolute',
top: 5,
left: 0
}}
>
一些操作
</a>
</div>
2017-10-25 16:41:38 +08:00
);
}
}
2017-01-11 17:01:50 +08:00
];
2016-12-26 22:04:16 +08:00
2017-01-11 17:01:50 +08:00
const data = [
2017-10-25 16:41:38 +08:00
{ a: "令狐冲", b: "男", c: 41, d: "操作", key: "1" },
2018-04-26 15:11:32 +08:00
{ a: "杨过叔叔的女儿黄蓉", b: "男", c: 67, d: "操作", key: "2" },
2017-10-25 16:41:38 +08:00
{ a: "郭靖", b: "男", c: 25, d: "操作", key: "3" }
2017-01-11 17:01:50 +08:00
];
2016-12-26 22:04:16 +08:00
2017-09-11 16:02:03 +08:00
class Demo1 extends Component {
2017-10-25 16:41:38 +08:00
render() {
return (
<Table
columns={columns}
data={data}
title={currentData => <div>标题: 这是一个标题</div>}
footer={currentData => <div>表尾: 我是小尾巴</div>}
2018-04-26 15:11:32 +08:00
/>
2017-10-25 16:41:38 +08:00
);
}
2016-12-26 16:52:39 +08:00
}
2017-08-30 13:31:26 +08:00
2017-09-08 15:07:55 +08:00
export default Demo1;