bee-table/demo/demolist/Demo14.js

313 lines
7.6 KiB
JavaScript
Raw Normal View History

2017-09-22 14:58:09 +08:00
/**
*
2017-10-12 16:54:17 +08:00
* @title 编辑态表格
* @description 这是带有多种不同格式的编辑态表格编辑态是通过使用不同的render来达到不同编辑格式
2017-09-22 14:58:09 +08:00
*
*/
import Button from "bee-button";
import React, { Component } from "react";
import Table from "../../src";
import Animate from "bee-animate";
import Tooltip from "bee-tooltip";
2017-09-22 14:58:09 +08:00
import Icon from "bee-icon";
import Input from "bee-form-control";
import Checkbox from "bee-checkbox";
2017-09-26 15:00:11 +08:00
import Select from "bee-select";
2017-09-22 14:58:09 +08:00
import InputRender from "../../src/render/InputRender.js";
2017-09-26 15:00:11 +08:00
import DateRender from "../../src/render/DateRender.js";
import SelectRender from "../../src/render/SelectRender.js";
2017-09-22 14:58:09 +08:00
2017-09-25 11:18:46 +08:00
//日期控件引入
2017-09-26 15:00:11 +08:00
import DatePicker from "bee-datepicker";
import MonthPicker, { WeekPicker, RangePicker } from "bee-datepicker";
2017-09-25 11:18:46 +08:00
2017-09-26 15:00:11 +08:00
const format = "YYYY-MM-DD";
const format2 = "YYYY-MM";
const format3 = "YYYY-MM-DD HH:mm:ss";
2017-09-25 11:18:46 +08:00
2017-09-26 15:00:11 +08:00
const dateInputPlaceholder = "选择日期";
const dateInputPlaceholder2 = "选择年月";
const dataSource = [
{
key: "boyuzhou",
value: "jack"
},
{
key: "renhualiu",
value: "lucy"
},
{
key: "yuzhao",
value: "yiminghe"
}
];
class Demo14 extends React.Component {
2017-09-22 14:58:09 +08:00
constructor(props) {
super(props);
this.state = {
dataSource: [
{
key: "0",
name: "沉鱼",
2017-10-23 14:02:30 +08:00
number: "10",
2017-09-22 14:58:09 +08:00
age: "y",
address: "jack",
datepicker: "2017-06-12",
MonthPicker: "2017-02"
2017-09-22 14:58:09 +08:00
},
{
key: "1",
name: "落雁",
2017-10-23 14:02:30 +08:00
number: "100",
2017-09-22 14:58:09 +08:00
age: "y",
2017-10-12 16:54:17 +08:00
address: "lucy",
datepicker: "2017-06-12",
MonthPicker: "2017-02"
2017-09-22 14:58:09 +08:00
},
{
key: "2",
name: "闭月",
2017-10-23 14:02:30 +08:00
number: "1000",
2017-09-22 14:58:09 +08:00
age: "n",
2017-10-12 16:54:17 +08:00
address: "lucy",
datepicker: "2017-06-12",
MonthPicker: "2017-02"
2017-09-22 14:58:09 +08:00
},
{
key: "3",
name: "羞花",
2017-10-23 14:02:30 +08:00
number: "9999",
2017-09-22 14:58:09 +08:00
age: "y",
2017-10-12 16:54:17 +08:00
address: "lucy",
datepicker: "2017-06-12",
MonthPicker: "2017-02"
2017-09-22 14:58:09 +08:00
}
],
count: 4
};
this.columns = [
{
2017-10-12 16:54:17 +08:00
title: "普通输入",
2017-09-22 14:58:09 +08:00
dataIndex: "name",
key: "name",
2017-10-23 14:02:30 +08:00
width: "150px",
2017-09-22 14:58:09 +08:00
render: (text, record, index) => (
<InputRender
name="name"
placeholder="请输入姓名"
2017-09-22 14:58:09 +08:00
value={text}
isclickTrigger={true}
check={this.check}
2017-09-26 15:00:11 +08:00
onChange={this.onInputChange(index, "name")}
isRequire={true}
method="blur"
errorMessage={
<Tooltip overlay={"错误提示"}>
<Icon type="uf-exc-c" className="" />
</Tooltip>
}
reg={/^[0-9]+$/}
2017-09-22 14:58:09 +08:00
/>
)
},
2017-10-23 14:02:30 +08:00
{
title: "货币输入",
dataIndex: "number",
key: "number",
width: "150px",
render: (text, record, index) => (
<InputRender
format="Currency"
name="name"
placeholder="请输入姓名"
value={text}
2017-10-23 14:02:30 +08:00
isclickTrigger={true}
check={this.check}
onChange={this.onInputChange(index, "name")}
isRequire={true}
method="blur"
errorMessage={
<Tooltip overlay={"错误提示"}>
<Icon type="uf-exc-c" className="" />
</Tooltip>
}
2017-10-23 14:02:30 +08:00
/>
)
},
2017-09-22 14:58:09 +08:00
{
2017-10-12 16:54:17 +08:00
title: "复选",
2017-09-22 14:58:09 +08:00
dataIndex: "age",
key: "age",
2017-09-26 15:00:11 +08:00
width: "100px",
2017-09-22 14:58:09 +08:00
render: (text, record, index) => (
<Checkbox
checked={record.age}
onChange={this.onCheckChange(index, "age")}
/>
)
},
{
2017-10-12 16:54:17 +08:00
title: "下拉框",
2017-09-22 14:58:09 +08:00
dataIndex: "address",
key: "address",
2017-09-26 15:00:11 +08:00
width: "200px",
2017-09-22 14:58:09 +08:00
render: (text, record, index) => {
return (
2017-09-26 15:00:11 +08:00
<SelectRender
dataSource={dataSource}
2017-09-26 15:00:11 +08:00
isclickTrigger={true}
2017-10-12 16:54:17 +08:00
value={text}
onChange={this.onSelectChange(index, "address")}
2017-09-22 14:58:09 +08:00
>
<Option value="jack">boyuzhou</Option>
<Option value="lucy">renhualiu</Option>
<Option value="disabled" disabled>
Disabled
</Option>
<Option value="yiminghe">yuzhao</Option>
2017-09-26 15:00:11 +08:00
</SelectRender>
2017-09-22 14:58:09 +08:00
);
}
},
2017-09-26 15:00:11 +08:00
{
title: "年月日",
2017-09-26 15:00:11 +08:00
dataIndex: "datepicker",
key: "datepicker",
width: "200px",
render: (text, record, index) => {
2017-09-26 15:00:11 +08:00
return (
<DateRender
value={text}
isclickTrigger={true}
2017-09-25 11:18:46 +08:00
format={format}
onSelect={this.onDateSelect}
onChange={this.onDateChange}
2017-09-26 15:00:11 +08:00
placeholder={dateInputPlaceholder}
/>
);
2017-09-25 11:18:46 +08:00
}
},
2017-09-26 15:00:11 +08:00
{
title: "年月",
dataIndex: "MonthPicker",
key: "MonthPicker",
width: "200px",
render: (text, record, index) => {
2017-09-26 15:00:11 +08:00
return (
<DateRender
value={text}
isclickTrigger={true}
format={format2}
onSelect={this.onSelect}
onChange={this.onChange}
2017-09-26 15:00:11 +08:00
placeholder={dateInputPlaceholder2}
/>
);
}
2017-09-22 14:58:09 +08:00
}
];
}
check = (flag, obj) => {
console.log(flag);
console.log(obj);
};
2017-09-26 15:00:11 +08:00
onInputChange = (index, key) => {
2017-09-22 14:58:09 +08:00
return value => {
const dataSource = [...this.state.dataSource];
dataSource[index][key] = value;
this.setState({ dataSource });
};
};
2017-09-26 15:00:11 +08:00
onCheckChange = (index, key) => {
2017-09-22 14:58:09 +08:00
return value => {
const dataSource = [...this.state.dataSource];
dataSource[index][key] = value;
this.setState({ dataSource });
};
};
onSelectChange = (index, key) => {
return value => {
console.log(`selected ${value}`);
const dataSource = [...this.state.dataSource];
dataSource[index][key] = value;
this.setState({ dataSource });
};
2017-09-26 15:00:11 +08:00
};
onDateChange = d => {
console.log(d);
};
onDateSelect = d => {
console.log(d);
};
2017-09-22 14:58:09 +08:00
onDelete = index => {
return () => {
const dataSource = [...this.state.dataSource];
dataSource.splice(index, 1);
this.setState({ dataSource });
};
};
handleAdd = () => {
const { count, dataSource } = this.state;
const newData = {
key: count,
name: `凤姐 ${count}`,
age: 32,
2017-10-12 16:54:17 +08:00
address: "jack",
datepicker: "2017-06-12",
2017-10-25 16:41:38 +08:00
MonthPicker: "2017-02"
2017-09-22 14:58:09 +08:00
};
this.setState({
dataSource: [...dataSource, newData],
count: count + 1
});
};
getBodyWrapper = body => {
return (
<Animate
transitionName="move"
component="tbody"
className={body.props.className}
>
{body.props.children}
</Animate>
);
};
getData = () => {
console.log(this.state.dataSource);
};
2017-09-22 14:58:09 +08:00
render() {
const { dataSource } = this.state;
const columns = this.columns;
return (
<div>
<Button
className="editable-add-btn"
type="ghost"
onClick={this.handleAdd}
>
添加一行
2017-09-22 14:58:09 +08:00
</Button>
<Button
style={{marginLeft:"5px"}}
className="editable-add-btn"
type="ghost"
onClick={this.getData}
>
获取数据
</Button>
2017-09-22 14:58:09 +08:00
<Table
bordered
data={dataSource}
columns={columns}
getBodyWrapper={this.getBodyWrapper}
/>
</div>
);
}
}
export default Demo14;