diff --git a/demo/TableDemo.scss b/demo/TableDemo.scss
index c85c48a..a4afa05 100644
--- a/demo/TableDemo.scss
+++ b/demo/TableDemo.scss
@@ -3,8 +3,51 @@
@import "../node_modules/bee-layout/src/Layout.scss";
@import "../node_modules/bee-button/src/Button.scss";
@import "../node_modules/bee-transition/src/Transition.scss";
-@import "../src/animation.scss";
-@import "../src/bordered.scss";
@import "../src/index.scss";
@import "../node_modules/bee-dropdown/src/Dropdown.scss";
@import "../node_modules/bee-menus/src/Menus.scss";
+@import "../node_modules/bee-popconfirm/src/Popconfirm.scss";
+@import "../node_modules/bee-form-control/src/FormControl.scss";
+
+.editable-cell {
+ position: relative;
+}
+
+.editable-cell-input-wrapper,
+.editable-cell-text-wrapper {
+ padding-right: 24px;
+}
+
+.editable-cell-text-wrapper {
+ padding: 5px 24px 5px 5px;
+}
+
+.editable-cell-icon,
+.editable-cell-icon-check {
+ position: absolute;
+ right: 0;
+ width: 20px;
+ cursor: pointer;
+}
+
+.editable-cell-icon {
+ line-height: 18px;
+ display: none;
+}
+
+.editable-cell-icon-check {
+ line-height: 28px;
+}
+
+.editable-cell:hover .editable-cell-icon {
+ display: inline-block;
+}
+
+.editable-cell-icon:hover,
+.editable-cell-icon-check:hover {
+ color:#2db7f5;
+}
+
+.editable-add-btn {
+ margin-bottom: 8px;
+}
diff --git a/demo/demolist/Demo1.js b/demo/demolist/Demo1.js
index 42a150f..95af22a 100644
--- a/demo/demolist/Demo1.js
+++ b/demo/demolist/Demo1.js
@@ -1,67 +1,36 @@
/**
*
-* @title 这是标题
-* @description 这是描述
+* @title 简单表格
+* @description
*
*/
-class Demo1 extends React.Component {
- constructor(props) {
- super(props);
- this.columns = [
- { title: 'title1', dataIndex: 'a', key: 'a', width: 100 },
- { id: '123', title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
- { title: 'title3', dataIndex: 'c', key: 'c', width: 200 },
- {
- title: 'Operations', dataIndex: '', key: 'd', render: (text, record) =>
- this.onDelete(record.key, e)} href="#">Delete,
- },
- ];
- this.state = {
- data: [
- { a: '123', key: '1' },
- { a: 'cdd', b: 'edd', key: '2' },
- { a: '1333', c: 'eee', key: '3' },
- ],
- };
- }
- onDelete(key, e) {
- console.log('Delete', key);
- e.preventDefault();
- const data = this.state.data.filter(item => item.key !== key);
- this.setState({ data });
- }
+const columns = [
+ { title: '用户名', dataIndex: 'a', key: 'a', width: 100 },
+ { id: '123', title: '性别', dataIndex: 'b', key: 'b', width: 100 },
+ { title: '年龄', dataIndex: 'c', key: 'c', width: 200 },
+ {
+ title: '操作', dataIndex: '', key: 'd', render() {
+ return 一些操作;
+ },
+ },
+];
- onAdd() {
- const data = [...this.state.data];
- data.push({
- a: 'new data',
- b: 'new data',
- c: 'new data',
- key: Date.now(),
- });
- this.setState({ data });
- }
+const data = [
+ { a: '令狐冲', b: '男', c: 41, key: '1' },
+ { a: '杨过', b: '男', c: 67, key: '2' },
+ { a: '郭靖', b: '男', c: 25, key: '3' },
+];
- getBodyWrapper(body) {
- return (
-
- {body.props.children}
-
- );
- }
-
- render() {
- return (
-
-
Table row with animation
-
-
-
- );
- }
+class Demo1 extends Component {
+ render () {
+ return (
+ 标题: {currentData.length} 个元素
}
+ footer={currentData => 表尾: {currentData.length} 个元素
}
+ />
+ )
+ }
}
diff --git a/demo/demolist/Demo2.js b/demo/demolist/Demo2.js
index 35e1f91..28e2312 100644
--- a/demo/demolist/Demo2.js
+++ b/demo/demolist/Demo2.js
@@ -5,86 +5,166 @@
*
*/
-const columns1 = [{
- title: 'Name',
- dataIndex: 'name',
- key: 'name',
- width: 400,
-}, {
- title: 'Age',
- dataIndex: 'age',
- key: 'age',
- width: 100,
-}, {
- title: 'Address',
- dataIndex: 'address',
- key: 'address',
- width: 200,
-}, {
- title: 'Operations',
- dataIndex: 'operation',
- key: 'x',
- width: 150,
-}];
-
-const data1 = [{
- key: 1,
- name: 'a',
- age: 32,
- address: 'I am a',
- children: [{
- key: 11,
- name: 'aa',
- age: 33,
- address: 'I am aa',
- }, {
- key: 12,
- name: 'ab',
- age: 33,
- address: 'I am ab',
- children: [{
- key: 121,
- name: 'aba',
- age: 33,
- address: 'I am aba',
- }],
- }, {
- key: 13,
- name: 'ac',
- age: 33,
- address: 'I am ac',
- children: [{
- key: 131,
- name: 'aca',
- age: 33,
- address: 'I am aca',
- children: [{
- key: 1311,
- name: 'acaa',
- age: 33,
- address: 'I am acaa',
- }, {
- key: 1312,
- name: 'acab',
- age: 33,
- address: 'I am acab',
- }],
- }],
- }],
-}, {
- key: 2,
- name: 'b',
- age: 32,
- address: 'I am b',
-}];
-
-function onExpand(expanded, record) {
- console.log('onExpand', expanded, record);
-}
-class Demo2 extends Component {
- render () {
- return (
-
- )
+class EditableCell extends React.Component {
+ state = {
+ value: this.props.value,
+ editable: false,
+ }
+ handleChange = (e) => {
+ const value = e.target.value;
+ this.setState({ value });
+ }
+ check = () => {
+ this.setState({ editable: false });
+ if (this.props.onChange) {
+ this.props.onChange(this.state.value);
}
+ }
+ edit = () => {
+ this.setState({ editable: true });
+ }
+ handleKeydown = (event) => {
+ console.log(event);
+ if(event.keyCode == 13){
+ this.check();
+ }
+
+ }
+ render() {
+ const { value, editable } = this.state;
+ return (
+ {
+ editable ?
+
+
+
+
+ :
+
+ {value || ' '}
+
+
+ }
+
);
+ }
+}
+
+class Demo2 extends React.Component {
+ constructor(props) {
+ super(props);
+ this.columns = [{
+ title: '姓名',
+ dataIndex: 'name',
+ key:'name',
+ width: '30%',
+ render: (text, record, index) => (
+
+ ),
+ }, {
+ title: '年龄',
+ dataIndex: 'age',
+ key:'age',
+ }, {
+ title: '你懂的',
+ dataIndex: 'address',
+ key:'address',
+ }, {
+ title: '操作',
+ dataIndex: 'operation',
+ key: 'operation',
+ render: (text, record, index) => {
+ return (
+ this.state.dataSource.length > 1 ?
+ (
+
+
+
+ ) : null
+ );
+ },
+ }];
+
+ this.state = {
+ dataSource: [{
+ key: '0',
+ name: '沉鱼',
+ age: '18',
+ address: '96, 77, 89',
+ }, {
+ key: '1',
+ name: '落雁',
+ age: '16',
+ address: '90, 70, 80',
+ }, {
+ key: '2',
+ name: '闭月',
+ age: '17',
+ address: '80, 60, 80',
+ }, {
+ key: '3',
+ name: '羞花',
+ age: '20',
+ address: '120, 60, 90',
+ }],
+ count: 4,
+ };
+ }
+ onCellChange = (index, key) => {
+ return (value) => {
+ const dataSource = [...this.state.dataSource];
+ dataSource[index][key] = value;
+ this.setState({ dataSource });
+ };
+ }
+ 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,
+ address: `100 100 100`,
+ };
+ this.setState({
+ dataSource: [...dataSource, newData],
+ count: count + 1,
+ });
+ }
+
+ getBodyWrapper = (body) => {
+ return (
+
+ {body.props.children}
+
+ );
+ }
+ render() {
+ const { dataSource } = this.state;
+ const columns = this.columns;
+ return ();
+ }
}
diff --git a/demo/demolist/Demo3.js b/demo/demolist/Demo3.js
deleted file mode 100644
index 515a551..0000000
--- a/demo/demolist/Demo3.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
-*
-* @title 这是标题
-* @description 这是描述
-*
-*/
-
-const columns2 = [
- { title: 'title1', dataIndex: 'a',
- className: 'a',
- key: 'a', width: 100 },
- { id: '123', title: 'title2', dataIndex: 'b',
- className: 'b',
- key: 'b', width: 100 },
- { title: 'title3', dataIndex: 'c',
- className: 'c',
- key: 'c', width: 200 },
- {
- title: 'Operations', dataIndex: '',
- className: 'd',
- key: 'd', render() {
- return Operations;
- },
- },
-];
-
-const data2 = [
- { a: '123', key: '1' },
- { a: 'cdd', b: 'edd', key: '2' },
- { a: '1333', c: 'eee', d: 2, key: '3' },
-];
-
-class Demo3 extends Component {
- render () {
- return (
-
-
rowClassName and className
-
`row-${i}`}
- expandedRowRender={record => extra: {record.a}
}
- expandedRowClassName={(record, i) => `ex-row-${i}`}
- data={data2}
- className="table"
- />
-
- )
- }
-}
diff --git a/demo/demolist/Demo4.js b/demo/demolist/Demo4.js
deleted file mode 100644
index 9b17fd7..0000000
--- a/demo/demolist/Demo4.js
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
-*
-* @title 这是标题
-* @description 这是描述
-*
-*/
-
-const columns3 = [
- { title: '手机号', dataIndex: 'a', colSpan: 2, width: 100, key: 'a', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
- // 设置第一行为链接
- if (index === 0) {
- obj.children = {o};
- }
- // 第5行合并两列
- if (index === 4) {
- obj.props.colSpan = 2;
- }
-
- if (index === 5) {
- obj.props.colSpan = 6;
- }
- return obj;
- } },
- { title: '电话', dataIndex: 'b', colSpan: 0, width: 100, key: 'b', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
- // 列合并掉的表格设置colSpan=0,不会去渲染
- if (index === 4 || index === 5) {
- obj.props.colSpan = 0;
- }
- return obj;
- } },
- { title: 'Name', dataIndex: 'c', width: 100, key: 'c', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
-
- if (index === 5) {
- obj.props.colSpan = 0;
- }
- return obj;
- } },
- { title: 'Address', dataIndex: 'd', width: 200, key: 'd', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
- if (index === 0) {
- obj.props.rowSpan = 2;
- }
- if (index === 1 || index === 5) {
- obj.props.rowSpan = 0;
- }
-
- return obj;
- } },
- { title: 'Gender', dataIndex: 'e', width: 200, key: 'e', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
- if (index === 5) {
- obj.props.colSpan = 0;
- }
- return obj;
- } },
- {
- title: 'Operations', dataIndex: '', key: 'f',
- render(o, row, index) {
- if (index === 5) {
- return {
- props: {
- colSpan: 0,
- },
- };
- }
- return Operations;
- },
- },
-];
-
-const data3 = [
- { a: '13812340987', b: '0571-12345678', c: '张三', d: '文一西路', e: 'Male', key: '1' },
- { a: '13812340986', b: '0571-98787658', c: '张夫人', d: '文一西路', e: 'Female', key: '2' },
- { a: '13812988888', b: '0571-099877', c: '李四', d: '文二西路', e: 'Male', key: '3' },
- { a: '1381200008888', b: '0571-099877', c: '王五', d: '文二西路', e: 'Male', key: '4' },
- { a: '0571-88888110', c: '李警官', d: '武林门', e: 'Male', key: '5' },
- { a: '资料统计完毕于xxxx年xxx月xxx日', key: '6' },
-];
-
-
-class Demo4 extends Component {
- render () {
- return (
-
- )
- }
-}
diff --git a/demo/demolist/Demo5.js b/demo/demolist/Demo5.js
deleted file mode 100644
index a894084..0000000
--- a/demo/demolist/Demo5.js
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
-*
-* @title 这是标题
-* @description 这是描述
-*
-*/
-
-
-const data = [];
-for (let i = 0; i < 10; i++) {
- data.push({
- key: i,
- a: `a${i}`,
- b: `b${i}`,
- c: `c${i}`,
- });
-}
-
-const Demo5 = React.createClass({
- getInitialState() {
- this.filters = [];
- return {
- visible: false,
- };
- },
-
- handleVisibleChange(visible) {
- this.setState({ visible });
- },
-
- handleSelect(selected) {
- this.filters.push(selected);
- },
-
- handleDeselect(key) {
- const index = this.filters.indexOf(key);
- if (index !== -1) {
- this.filters.splice(index, 1);
- }
- },
-
- confirmFilter() {
- console.log(this.filters.join(','));
- this.setState({
- visible: false,
- });
- },
-
- render() {
- const menu = (
-
- );
-
- const columns = [
- {
- title: (
-
- ), key: 'a', dataIndex: 'a', width: 100,
- },
- { title: 'title2', key: 'b', dataIndex: 'b', width: 100 },
- { title: 'title3', key: 'c', dataIndex: 'c', width: 200 },
- ];
-
- return (
- record.key}
- />
- );
- },
-});
diff --git a/demo/index-demo-base.js b/demo/index-demo-base.js
index e5eed99..2e80a6c 100644
--- a/demo/index-demo-base.js
+++ b/demo/index-demo-base.js
@@ -8,11 +8,13 @@ import Table from '../src';
import Animate from 'bee-animate';
import Menu, { Item, Divider } from 'bee-menus';
import DropDown from 'bee-dropdown';
+import Icon from "bee-icon";
+import Input from 'bee-form-control';
+import Popconfirm from 'bee-popconfirm';
+const CARET = ;
-const CARET = ;
-
-const CARETUP = ;
+const CARETUP = ;
{demolist}
@@ -42,14 +44,9 @@ class Demo extends Component {
);
const header = (
-
+
{ example }
-
-
-
);
return (
diff --git a/demo/index.js b/demo/index.js
index b95cef0..6839f03 100644
--- a/demo/index.js
+++ b/demo/index.js
@@ -8,434 +8,222 @@ import Table from '../src';
import Animate from 'bee-animate';
import Menu, { Item, Divider } from 'bee-menus';
import DropDown from 'bee-dropdown';
+import Icon from "bee-icon";
+import Input from 'bee-form-control';
+import Popconfirm from 'bee-popconfirm';
+
+const CARET = ;
+
+const CARETUP = ;
-const CARET = ;
+/**
+*
+* @title 简单表格
+* @description
+*
+*/
-const CARETUP = ;
+const columns = [
+ { title: '用户名', dataIndex: 'a', key: 'a', width: 100 },
+ { id: '123', title: '性别', dataIndex: 'b', key: 'b', width: 100 },
+ { title: '年龄', dataIndex: 'c', key: 'c', width: 200 },
+ {
+ title: '操作', dataIndex: '', key: 'd', render() {
+ return 一些操作;
+ },
+ },
+];
+const data = [
+ { a: '令狐冲', b: '男', c: 41, key: '1' },
+ { a: '杨过', b: '男', c: 67, key: '2' },
+ { a: '郭靖', b: '男', c: 25, key: '3' },
+];
+class Demo1 extends Component {
+ render () {
+ return (
+ 标题: {currentData.length} 个元素
}
+ footer={currentData => 表尾: {currentData.length} 个元素
}
+ />
+ )
+ }
+}
/**
*
* @title 这是标题
* @description 这是描述
*
*/
-class Demo1 extends React.Component {
+
+class EditableCell extends React.Component {
+ state = {
+ value: this.props.value,
+ editable: false,
+ }
+ handleChange = (e) => {
+ const value = e.target.value;
+ this.setState({ value });
+ }
+ check = () => {
+ this.setState({ editable: false });
+ if (this.props.onChange) {
+ this.props.onChange(this.state.value);
+ }
+ }
+ edit = () => {
+ this.setState({ editable: true });
+ }
+ handleKeydown = (event) => {
+ console.log(event);
+ if(event.keyCode == 13){
+ this.check();
+ }
+
+ }
+ render() {
+ const { value, editable } = this.state;
+ return (
+ {
+ editable ?
+
+
+
+
+ :
+
+ {value || ' '}
+
+
+ }
+
);
+ }
+}
+
+class Demo2 extends React.Component {
constructor(props) {
super(props);
- this.columns = [
- { title: 'title1', dataIndex: 'a', key: 'a', width: 100 },
- { id: '123', title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
- { title: 'title3', dataIndex: 'c', key: 'c', width: 200 },
- {
- title: 'Operations', dataIndex: '', key: 'd', render: (text, record) =>
- this.onDelete(record.key, e)} href="#">Delete,
+ this.columns = [{
+ title: '姓名',
+ dataIndex: 'name',
+ key:'name',
+ width: '30%',
+ render: (text, record, index) => (
+
+ ),
+ }, {
+ title: '年龄',
+ dataIndex: 'age',
+ key:'age',
+ }, {
+ title: '你懂的',
+ dataIndex: 'address',
+ key:'address',
+ }, {
+ title: '操作',
+ dataIndex: 'operation',
+ key: 'operation',
+ render: (text, record, index) => {
+ return (
+ this.state.dataSource.length > 1 ?
+ (
+
+
+
+ ) : null
+ );
},
- ];
+ }];
+
this.state = {
- data: [
- { a: '123', key: '1' },
- { a: 'cdd', b: 'edd', key: '2' },
- { a: '1333', c: 'eee', key: '3' },
- ],
+ dataSource: [{
+ key: '0',
+ name: '沉鱼',
+ age: '18',
+ address: '96, 77, 89',
+ }, {
+ key: '1',
+ name: '落雁',
+ age: '16',
+ address: '90, 70, 80',
+ }, {
+ key: '2',
+ name: '闭月',
+ age: '17',
+ address: '80, 60, 80',
+ }, {
+ key: '3',
+ name: '羞花',
+ age: '20',
+ address: '120, 60, 90',
+ }],
+ count: 4,
};
}
-
- onDelete(key, e) {
- console.log('Delete', key);
- e.preventDefault();
- const data = this.state.data.filter(item => item.key !== key);
- this.setState({ data });
+ onCellChange = (index, key) => {
+ return (value) => {
+ const dataSource = [...this.state.dataSource];
+ dataSource[index][key] = value;
+ this.setState({ dataSource });
+ };
}
-
- onAdd() {
- const data = [...this.state.data];
- data.push({
- a: 'new data',
- b: 'new data',
- c: 'new data',
- key: Date.now(),
+ 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,
+ address: `100 100 100`,
+ };
+ this.setState({
+ dataSource: [...dataSource, newData],
+ count: count + 1,
});
- this.setState({ data });
}
- getBodyWrapper(body) {
+ getBodyWrapper = (body) => {
return (
{body.props.children}
);
}
-
render() {
- return (
-
-
Table row with animation
-
-
-
- );
+ const { dataSource } = this.state;
+ const columns = this.columns;
+ return ();
}
}
-/**
-*
-* @title 这是标题
-* @description 这是描述
-*
-*/
-
-const columns1 = [{
- title: 'Name',
- dataIndex: 'name',
- key: 'name',
- width: 400,
-}, {
- title: 'Age',
- dataIndex: 'age',
- key: 'age',
- width: 100,
-}, {
- title: 'Address',
- dataIndex: 'address',
- key: 'address',
- width: 200,
-}, {
- title: 'Operations',
- dataIndex: 'operation',
- key: 'x',
- width: 150,
-}];
-
-const data1 = [{
- key: 1,
- name: 'a',
- age: 32,
- address: 'I am a',
- children: [{
- key: 11,
- name: 'aa',
- age: 33,
- address: 'I am aa',
- }, {
- key: 12,
- name: 'ab',
- age: 33,
- address: 'I am ab',
- children: [{
- key: 121,
- name: 'aba',
- age: 33,
- address: 'I am aba',
- }],
- }, {
- key: 13,
- name: 'ac',
- age: 33,
- address: 'I am ac',
- children: [{
- key: 131,
- name: 'aca',
- age: 33,
- address: 'I am aca',
- children: [{
- key: 1311,
- name: 'acaa',
- age: 33,
- address: 'I am acaa',
- }, {
- key: 1312,
- name: 'acab',
- age: 33,
- address: 'I am acab',
- }],
- }],
- }],
-}, {
- key: 2,
- name: 'b',
- age: 32,
- address: 'I am b',
-}];
-
-function onExpand(expanded, record) {
- console.log('onExpand', expanded, record);
-}
-class Demo2 extends Component {
- render () {
- return (
-
- )
- }
-}
-/**
-*
-* @title 这是标题
-* @description 这是描述
-*
-*/
-
-const columns2 = [
- { title: 'title1', dataIndex: 'a',
- className: 'a',
- key: 'a', width: 100 },
- { id: '123', title: 'title2', dataIndex: 'b',
- className: 'b',
- key: 'b', width: 100 },
- { title: 'title3', dataIndex: 'c',
- className: 'c',
- key: 'c', width: 200 },
- {
- title: 'Operations', dataIndex: '',
- className: 'd',
- key: 'd', render() {
- return Operations;
- },
- },
-];
-
-const data2 = [
- { a: '123', key: '1' },
- { a: 'cdd', b: 'edd', key: '2' },
- { a: '1333', c: 'eee', d: 2, key: '3' },
-];
-
-class Demo3 extends Component {
- render () {
- return (
-
-
rowClassName and className
-
`row-${i}`}
- expandedRowRender={record => extra: {record.a}
}
- expandedRowClassName={(record, i) => `ex-row-${i}`}
- data={data2}
- className="table"
- />
-
- )
- }
-}
-/**
-*
-* @title 这是标题
-* @description 这是描述
-*
-*/
-
-const columns3 = [
- { title: '手机号', dataIndex: 'a', colSpan: 2, width: 100, key: 'a', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
- // 设置第一行为链接
- if (index === 0) {
- obj.children = {o};
- }
- // 第5行合并两列
- if (index === 4) {
- obj.props.colSpan = 2;
- }
-
- if (index === 5) {
- obj.props.colSpan = 6;
- }
- return obj;
- } },
- { title: '电话', dataIndex: 'b', colSpan: 0, width: 100, key: 'b', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
- // 列合并掉的表格设置colSpan=0,不会去渲染
- if (index === 4 || index === 5) {
- obj.props.colSpan = 0;
- }
- return obj;
- } },
- { title: 'Name', dataIndex: 'c', width: 100, key: 'c', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
-
- if (index === 5) {
- obj.props.colSpan = 0;
- }
- return obj;
- } },
- { title: 'Address', dataIndex: 'd', width: 200, key: 'd', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
- if (index === 0) {
- obj.props.rowSpan = 2;
- }
- if (index === 1 || index === 5) {
- obj.props.rowSpan = 0;
- }
-
- return obj;
- } },
- { title: 'Gender', dataIndex: 'e', width: 200, key: 'e', render(o, row, index) {
- const obj = {
- children: o,
- props: {},
- };
- if (index === 5) {
- obj.props.colSpan = 0;
- }
- return obj;
- } },
- {
- title: 'Operations', dataIndex: '', key: 'f',
- render(o, row, index) {
- if (index === 5) {
- return {
- props: {
- colSpan: 0,
- },
- };
- }
- return Operations;
- },
- },
-];
-
-const data3 = [
- { a: '13812340987', b: '0571-12345678', c: '张三', d: '文一西路', e: 'Male', key: '1' },
- { a: '13812340986', b: '0571-98787658', c: '张夫人', d: '文一西路', e: 'Female', key: '2' },
- { a: '13812988888', b: '0571-099877', c: '李四', d: '文二西路', e: 'Male', key: '3' },
- { a: '1381200008888', b: '0571-099877', c: '王五', d: '文二西路', e: 'Male', key: '4' },
- { a: '0571-88888110', c: '李警官', d: '武林门', e: 'Male', key: '5' },
- { a: '资料统计完毕于xxxx年xxx月xxx日', key: '6' },
-];
-
-
-class Demo4 extends Component {
- render () {
- return (
-
- )
- }
-}
-/**
-*
-* @title 这是标题
-* @description 这是描述
-*
-*/
-
-
-const data = [];
-for (let i = 0; i < 10; i++) {
- data.push({
- key: i,
- a: `a${i}`,
- b: `b${i}`,
- c: `c${i}`,
- });
-}
-
-const Demo5 = React.createClass({
- getInitialState() {
- this.filters = [];
- return {
- visible: false,
- };
- },
-
- handleVisibleChange(visible) {
- this.setState({ visible });
- },
-
- handleSelect(selected) {
- this.filters.push(selected);
- },
-
- handleDeselect(key) {
- const index = this.filters.indexOf(key);
- if (index !== -1) {
- this.filters.splice(index, 1);
- }
- },
-
- confirmFilter() {
- console.log(this.filters.join(','));
- this.setState({
- visible: false,
- });
- },
-
- render() {
- const menu = (
-
- );
-
- const columns = [
- {
- title: (
-
- ), key: 'a', dataIndex: 'a', width: 100,
- },
- { title: 'title2', key: 'b', dataIndex: 'b', width: 100 },
- { title: 'title3', key: 'c', dataIndex: 'c', width: 200 },
- ];
-
- return (
- record.key}
- />
- );
- },
-});
-var DemoArray = [{"example":,"title":" 这是标题","code":"/**\n*\n* @title 这是标题\n* @description 这是描述\n*\n*/\nclass Demo1 extends React.Component {\n constructor(props) {\n super(props);\n this.columns = [\n { title: 'title1', dataIndex: 'a', key: 'a', width: 100 },\n { id: '123', title: 'title2', dataIndex: 'b', key: 'b', width: 100 },\n { title: 'title3', dataIndex: 'c', key: 'c', width: 200 },\n {\n title: 'Operations', dataIndex: '', key: 'd', render: (text, record) =>\n this.onDelete(record.key, e)} href=\"#\">Delete,\n },\n ];\n this.state = {\n data: [\n { a: '123', key: '1' },\n { a: 'cdd', b: 'edd', key: '2' },\n { a: '1333', c: 'eee', key: '3' },\n ],\n };\n }\n\n onDelete(key, e) {\n console.log('Delete', key);\n e.preventDefault();\n const data = this.state.data.filter(item => item.key !== key);\n this.setState({ data });\n }\n\n onAdd() {\n const data = [...this.state.data];\n data.push({\n a: 'new data',\n b: 'new data',\n c: 'new data',\n key: Date.now(),\n });\n this.setState({ data });\n }\n\n getBodyWrapper(body) {\n return (\n \n {body.props.children}\n \n );\n }\n\n render() {\n return (\n \n
Table row with animation
\n
\n
\n
\n );\n }\n}\n","desc":" 这是描述"},{"example":,"title":" 这是标题","code":"/**\r\n*\r\n* @title 这是标题\r\n* @description 这是描述\r\n*\r\n*/\r\n\r\nconst columns1 = [{\r\n title: 'Name',\r\n dataIndex: 'name',\r\n key: 'name',\r\n width: 400,\r\n}, {\r\n title: 'Age',\r\n dataIndex: 'age',\r\n key: 'age',\r\n width: 100,\r\n}, {\r\n title: 'Address',\r\n dataIndex: 'address',\r\n key: 'address',\r\n width: 200,\r\n}, {\r\n title: 'Operations',\r\n dataIndex: 'operation',\r\n key: 'x',\r\n width: 150,\r\n}];\r\n\r\nconst data1 = [{\r\n key: 1,\r\n name: 'a',\r\n age: 32,\r\n address: 'I am a',\r\n children: [{\r\n key: 11,\r\n name: 'aa',\r\n age: 33,\r\n address: 'I am aa',\r\n }, {\r\n key: 12,\r\n name: 'ab',\r\n age: 33,\r\n address: 'I am ab',\r\n children: [{\r\n key: 121,\r\n name: 'aba',\r\n age: 33,\r\n address: 'I am aba',\r\n }],\r\n }, {\r\n key: 13,\r\n name: 'ac',\r\n age: 33,\r\n address: 'I am ac',\r\n children: [{\r\n key: 131,\r\n name: 'aca',\r\n age: 33,\r\n address: 'I am aca',\r\n children: [{\r\n key: 1311,\r\n name: 'acaa',\r\n age: 33,\r\n address: 'I am acaa',\r\n }, {\r\n key: 1312,\r\n name: 'acab',\r\n age: 33,\r\n address: 'I am acab',\r\n }],\r\n }],\r\n }],\r\n}, {\r\n key: 2,\r\n name: 'b',\r\n age: 32,\r\n address: 'I am b',\r\n}];\r\n\r\nfunction onExpand(expanded, record) {\r\n console.log('onExpand', expanded, record);\r\n}\r\nclass Demo2 extends Component {\r\n render () {\r\n return (\r\n \r\n )\r\n }\r\n}\r\n","desc":" 这是描述"},{"example":,"title":" 这是标题","code":"/**\r\n*\r\n* @title 这是标题\r\n* @description 这是描述\r\n*\r\n*/\r\n\r\nconst columns2 = [\r\n { title: 'title1', dataIndex: 'a',\r\n className: 'a',\r\n key: 'a', width: 100 },\r\n { id: '123', title: 'title2', dataIndex: 'b',\r\n className: 'b',\r\n key: 'b', width: 100 },\r\n { title: 'title3', dataIndex: 'c',\r\n className: 'c',\r\n key: 'c', width: 200 },\r\n {\r\n title: 'Operations', dataIndex: '',\r\n className: 'd',\r\n key: 'd', render() {\r\n return Operations;\r\n },\r\n },\r\n];\r\n\r\nconst data2 = [\r\n { a: '123', key: '1' },\r\n { a: 'cdd', b: 'edd', key: '2' },\r\n { a: '1333', c: 'eee', d: 2, key: '3' },\r\n];\r\n\r\nclass Demo3 extends Component {\r\n render () {\r\n return (\r\n \r\n
rowClassName and className
\r\n
`row-${i}`}\r\n expandedRowRender={record => extra: {record.a}
}\r\n expandedRowClassName={(record, i) => `ex-row-${i}`}\r\n data={data2}\r\n className=\"table\"\r\n />\r\n \r\n )\r\n }\r\n}\r\n","desc":" 这是描述"},{"example":,"title":" 这是标题","code":"/**\r\n*\r\n* @title 这是标题\r\n* @description 这是描述\r\n*\r\n*/\r\n\r\nconst columns3 = [\r\n { title: '手机号', dataIndex: 'a', colSpan: 2, width: 100, key: 'a', render(o, row, index) {\r\n const obj = {\r\n children: o,\r\n props: {},\r\n };\r\n // 设置第一行为链接\r\n if (index === 0) {\r\n obj.children = {o};\r\n }\r\n // 第5行合并两列\r\n if (index === 4) {\r\n obj.props.colSpan = 2;\r\n }\r\n\r\n if (index === 5) {\r\n obj.props.colSpan = 6;\r\n }\r\n return obj;\r\n } },\r\n { title: '电话', dataIndex: 'b', colSpan: 0, width: 100, key: 'b', render(o, row, index) {\r\n const obj = {\r\n children: o,\r\n props: {},\r\n };\r\n // 列合并掉的表格设置colSpan=0,不会去渲染\r\n if (index === 4 || index === 5) {\r\n obj.props.colSpan = 0;\r\n }\r\n return obj;\r\n } },\r\n { title: 'Name', dataIndex: 'c', width: 100, key: 'c', render(o, row, index) {\r\n const obj = {\r\n children: o,\r\n props: {},\r\n };\r\n\r\n if (index === 5) {\r\n obj.props.colSpan = 0;\r\n }\r\n return obj;\r\n } },\r\n { title: 'Address', dataIndex: 'd', width: 200, key: 'd', render(o, row, index) {\r\n const obj = {\r\n children: o,\r\n props: {},\r\n };\r\n if (index === 0) {\r\n obj.props.rowSpan = 2;\r\n }\r\n if (index === 1 || index === 5) {\r\n obj.props.rowSpan = 0;\r\n }\r\n\r\n return obj;\r\n } },\r\n { title: 'Gender', dataIndex: 'e', width: 200, key: 'e', render(o, row, index) {\r\n const obj = {\r\n children: o,\r\n props: {},\r\n };\r\n if (index === 5) {\r\n obj.props.colSpan = 0;\r\n }\r\n return obj;\r\n } },\r\n {\r\n title: 'Operations', dataIndex: '', key: 'f',\r\n render(o, row, index) {\r\n if (index === 5) {\r\n return {\r\n props: {\r\n colSpan: 0,\r\n },\r\n };\r\n }\r\n return Operations;\r\n },\r\n },\r\n];\r\n\r\nconst data3 = [\r\n { a: '13812340987', b: '0571-12345678', c: '张三', d: '文一西路', e: 'Male', key: '1' },\r\n { a: '13812340986', b: '0571-98787658', c: '张夫人', d: '文一西路', e: 'Female', key: '2' },\r\n { a: '13812988888', b: '0571-099877', c: '李四', d: '文二西路', e: 'Male', key: '3' },\r\n { a: '1381200008888', b: '0571-099877', c: '王五', d: '文二西路', e: 'Male', key: '4' },\r\n { a: '0571-88888110', c: '李警官', d: '武林门', e: 'Male', key: '5' },\r\n { a: '资料统计完毕于xxxx年xxx月xxx日', key: '6' },\r\n];\r\n\r\n\r\nclass Demo4 extends Component {\r\n render () {\r\n return (\r\n \r\n
colSpan & rowSpan
\r\n
\r\n
\r\n )\r\n }\r\n}\r\n","desc":" 这是描述"},{"example":,"title":" 这是标题","code":"/**\r\n*\r\n* @title 这是标题\r\n* @description 这是描述\r\n*\r\n*/\r\n\r\n\r\nconst data = [];\r\nfor (let i = 0; i < 10; i++) {\r\n data.push({\r\n key: i,\r\n a: `a${i}`,\r\n b: `b${i}`,\r\n c: `c${i}`,\r\n });\r\n}\r\n\r\nconst Demo5 = React.createClass({\r\n getInitialState() {\r\n this.filters = [];\r\n return {\r\n visible: false,\r\n };\r\n },\r\n\r\n handleVisibleChange(visible) {\r\n this.setState({ visible });\r\n },\r\n\r\n handleSelect(selected) {\r\n this.filters.push(selected);\r\n },\r\n\r\n handleDeselect(key) {\r\n const index = this.filters.indexOf(key);\r\n if (index !== -1) {\r\n this.filters.splice(index, 1);\r\n }\r\n },\r\n\r\n confirmFilter() {\r\n console.log(this.filters.join(','));\r\n this.setState({\r\n visible: false,\r\n });\r\n },\r\n\r\n render() {\r\n const menu = (\r\n \r\n );\r\n\r\n const columns = [\r\n {\r\n title: (\r\n \r\n title1\r\n
\r\n filter\r\n \r\n
\r\n ), key: 'a', dataIndex: 'a', width: 100,\r\n },\r\n { title: 'title2', key: 'b', dataIndex: 'b', width: 100 },\r\n { title: 'title3', key: 'c', dataIndex: 'c', width: 200 },\r\n ];\r\n\r\n return (\r\n record.key}\r\n />\r\n );\r\n },\r\n});\r\n","desc":" 这是描述"}]
+var DemoArray = [{"example":,"title":" 简单表格","code":"/**\r\n*\r\n* @title 简单表格\r\n* @description\r\n*\r\n*/\r\n\r\nconst columns = [\r\n { title: '用户名', dataIndex: 'a', key: 'a', width: 100 },\r\n { id: '123', title: '性别', dataIndex: 'b', key: 'b', width: 100 },\r\n { title: '年龄', dataIndex: 'c', key: 'c', width: 200 },\r\n {\r\n title: '操作', dataIndex: '', key: 'd', render() {\r\n return 一些操作;\r\n },\r\n },\r\n];\r\n\r\nconst data = [\r\n { a: '令狐冲', b: '男', c: 41, key: '1' },\r\n { a: '杨过', b: '男', c: 67, key: '2' },\r\n { a: '郭靖', b: '男', c: 25, key: '3' },\r\n];\r\n\r\nclass Demo1 extends Component {\r\n render () {\r\n return (\r\n 标题: {currentData.length} 个元素
}\r\n footer={currentData => 表尾: {currentData.length} 个元素
}\r\n />\r\n )\r\n }\r\n}\r\n","desc":""},{"example":,"title":" 这是标题","code":"/**\r\n*\r\n* @title 这是标题\r\n* @description 这是描述\r\n*\r\n*/\r\n\r\nclass EditableCell extends React.Component {\r\n state = {\r\n value: this.props.value,\r\n editable: false,\r\n }\r\n handleChange = (e) => {\r\n const value = e.target.value;\r\n this.setState({ value });\r\n }\r\n check = () => {\r\n this.setState({ editable: false });\r\n if (this.props.onChange) {\r\n this.props.onChange(this.state.value);\r\n }\r\n }\r\n edit = () => {\r\n this.setState({ editable: true });\r\n }\r\n handleKeydown = (event) => {\r\n console.log(event);\r\n if(event.keyCode == 13){\r\n this.check();\r\n }\r\n\r\n }\r\n render() {\r\n const { value, editable } = this.state;\r\n return (\r\n {\r\n editable ?\r\n
\r\n \r\n \r\n
\r\n :\r\n
\r\n {value || ' '}\r\n \r\n
\r\n }\r\n
);\r\n }\r\n}\r\n\r\nclass Demo2 extends React.Component {\r\n constructor(props) {\r\n super(props);\r\n this.columns = [{\r\n title: '姓名',\r\n dataIndex: 'name',\r\n key:'name',\r\n width: '30%',\r\n render: (text, record, index) => (\r\n \r\n ),\r\n }, {\r\n title: '年龄',\r\n dataIndex: 'age',\r\n key:'age',\r\n }, {\r\n title: '你懂的',\r\n dataIndex: 'address',\r\n key:'address',\r\n }, {\r\n title: '操作',\r\n dataIndex: 'operation',\r\n key: 'operation',\r\n render: (text, record, index) => {\r\n return (\r\n this.state.dataSource.length > 1 ?\r\n (\r\n \r\n \r\n \r\n ) : null\r\n );\r\n },\r\n }];\r\n\r\n this.state = {\r\n dataSource: [{\r\n key: '0',\r\n name: '沉鱼',\r\n age: '18',\r\n address: '96, 77, 89',\r\n }, {\r\n key: '1',\r\n name: '落雁',\r\n age: '16',\r\n address: '90, 70, 80',\r\n }, {\r\n key: '2',\r\n name: '闭月',\r\n age: '17',\r\n address: '80, 60, 80',\r\n }, {\r\n key: '3',\r\n name: '羞花',\r\n age: '20',\r\n address: '120, 60, 90',\r\n }],\r\n count: 4,\r\n };\r\n }\r\n onCellChange = (index, key) => {\r\n return (value) => {\r\n const dataSource = [...this.state.dataSource];\r\n dataSource[index][key] = value;\r\n this.setState({ dataSource });\r\n };\r\n }\r\n onDelete = (index) => {\r\n return () => {\r\n const dataSource = [...this.state.dataSource];\r\n dataSource.splice(index, 1);\r\n this.setState({ dataSource });\r\n };\r\n }\r\n handleAdd = () => {\r\n const { count, dataSource } = this.state;\r\n const newData = {\r\n key: count,\r\n name: `凤姐 ${count}`,\r\n age: 32,\r\n address: `100 100 100`,\r\n };\r\n this.setState({\r\n dataSource: [...dataSource, newData],\r\n count: count + 1,\r\n });\r\n }\r\n\r\n getBodyWrapper = (body) => {\r\n return (\r\n \r\n {body.props.children}\r\n \r\n );\r\n }\r\n render() {\r\n const { dataSource } = this.state;\r\n const columns = this.columns;\r\n return ();\r\n }\r\n}\r\n","desc":" 这是描述"}]
class Demo extends Component {
@@ -463,14 +251,9 @@ class Demo extends Component {
);
const header = (
-
+
{ example }
-
-
-
);
return (
diff --git a/package.json b/package.json
index d509103..dc8d991 100644
--- a/package.json
+++ b/package.json
@@ -41,18 +41,19 @@
"warning": "^3.0.0"
},
"devDependencies": {
- "bee-animate": "0.0.3",
+ "bee-animate": "latest",
"bee-button": "latest",
- "bee-dropdown": "^0.1.4",
+ "bee-form-control": "^0.1.7",
+ "bee-icon": "0.0.5",
"bee-layout": "latest",
- "bee-menus": "0.0.5",
"bee-panel": "latest",
+ "bee-popconfirm": "^0.2.1",
"chai": "^3.5.0",
"console-polyfill": "~0.2.1",
"enzyme": "^2.4.1",
"es5-shim": "~4.1.10",
- "react": "~0.14.0",
+ "react": "15.3.2",
"react-addons-test-utils": "15.3.2",
- "react-dom": "~0.14.0"
+ "react-dom": "15.3.2"
}
}
diff --git a/src/Column.jsx b/src/Column.js
similarity index 100%
rename from src/Column.jsx
rename to src/Column.js
diff --git a/src/ColumnGroup.jsx b/src/ColumnGroup.js
similarity index 100%
rename from src/ColumnGroup.jsx
rename to src/ColumnGroup.js
diff --git a/src/ColumnManager.js b/src/ColumnManager.js
index a143288..c482e4e 100644
--- a/src/ColumnManager.js
+++ b/src/ColumnManager.js
@@ -2,6 +2,8 @@ import React from 'react';
import Column from './Column';
import ColumnGroup from './ColumnGroup';
+//行控制管理
+
export default class ColumnManager {
_cached = {}
diff --git a/src/ExpandIcon.jsx b/src/ExpandIcon.js
similarity index 58%
rename from src/ExpandIcon.jsx
rename to src/ExpandIcon.js
index 358eff3..3ce20d6 100644
--- a/src/ExpandIcon.jsx
+++ b/src/ExpandIcon.js
@@ -1,33 +1,39 @@
-import React, { PropTypes } from 'react';
+import React, { PropTypes, Component } from 'react';
import shallowequal from 'shallowequal';
-const ExpandIcon = React.createClass({
- propTypes: {
+const propTypes = {
record: PropTypes.object,
- prefixCls: PropTypes.string,
+ clsPrefix: PropTypes.string,
expandable: PropTypes.any,
expanded: PropTypes.bool,
needIndentSpaced: PropTypes.bool,
onExpand: PropTypes.func,
- },
+};
+
+class ExpandIcon extends Component{
+ constructor(props){
+ super(props);
+ }
shouldComponentUpdate(nextProps) {
return !shallowequal(nextProps, this.props);
- },
+ }
render() {
- const { expandable, prefixCls, onExpand, needIndentSpaced, expanded, record } = this.props;
+ const { expandable, clsPrefix, onExpand, needIndentSpaced, expanded, record } = this.props;
if (expandable) {
const expandClassName = expanded ? 'expanded' : 'collapsed';
return (
onExpand(!expanded, record, e)}
/>
);
} else if (needIndentSpaced) {
- return ;
+ return ;
}
return null;
- },
-});
+ }
+};
+
+ExpandIcon.propTypes = propTypes;
export default ExpandIcon;
diff --git a/src/Table.jsx b/src/Table.js
similarity index 78%
rename from src/Table.jsx
rename to src/Table.js
index a73b558..e4e99c6 100644
--- a/src/Table.jsx
+++ b/src/Table.js
@@ -1,4 +1,4 @@
-import React, { PropTypes } from 'react';
+import React, { PropTypes, Component } from 'react';
import TableRow from './TableRow';
import TableHeader from './TableHeader';
import { measureScrollbar, debounce, warningOnce } from './utils';
@@ -7,8 +7,7 @@ import addEventListener from 'rc-util/lib/Dom/addEventListener';
import ColumnManager from './ColumnManager';
import createStore from './createStore';
-const Table = React.createClass({
- propTypes: {
+const propTypes = {
data: PropTypes.array,
expandIconAsCell: PropTypes.bool,
defaultExpandAllRows: PropTypes.bool,
@@ -16,9 +15,10 @@ const Table = React.createClass({
defaultExpandedRowKeys: PropTypes.array,
useFixedHeader: PropTypes.bool,
columns: PropTypes.array,
- prefixCls: PropTypes.string,
+ clsPrefix: PropTypes.string,
bodyStyle: PropTypes.object,
style: PropTypes.object,
+ //特殊的渲染规则的key值
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
rowClassName: PropTypes.func,
expandedRowClassName: PropTypes.func,
@@ -29,6 +29,7 @@ const Table = React.createClass({
onRowClick: PropTypes.func,
onRowDoubleClick: PropTypes.func,
expandIconColumnIndex: PropTypes.number,
+ //是否显示表头
showHeader: PropTypes.bool,
title: PropTypes.func,
footer: PropTypes.func,
@@ -37,61 +38,87 @@ const Table = React.createClass({
rowRef: PropTypes.func,
getBodyWrapper: PropTypes.func,
children: PropTypes.node,
- },
+};
- getDefaultProps() {
- return {
- data: [],
- useFixedHeader: false,
- expandIconAsCell: false,
- defaultExpandAllRows: false,
- defaultExpandedRowKeys: [],
- rowKey: 'key',
- rowClassName: () => '',
- expandedRowClassName: () => '',
- onExpand() {},
- onExpandedRowsChange() {},
- onRowClick() {},
- onRowDoubleClick() {},
- prefixCls: 'u-table',
- bodyStyle: {},
- style: {},
- childrenColumnName: 'children',
- indentSize: 15,
- expandIconColumnIndex: 0,
- showHeader: true,
- scroll: {},
- rowRef: () => null,
- getBodyWrapper: body => body,
- emptyText: () => 'No Data',
- };
- },
+const defaultProps = {
+ data: [],
+ useFixedHeader: false,
+ expandIconAsCell: false,
+ defaultExpandAllRows: false,
+ defaultExpandedRowKeys: [],
+ rowKey: 'key',
+ rowClassName: () => '',
+ expandedRowClassName: () => '',
+ onExpand() {},
+ onExpandedRowsChange() {},
+ onRowClick() {},
+ onRowDoubleClick() {},
+ clsPrefix: 'u-table',
+ bodyStyle: {},
+ style: {},
+ childrenColumnName: 'children',
+ indentSize: 15,
+ expandIconColumnIndex: 0,
+ showHeader: true,
+ scroll: {},
+ rowRef: () => null,
+ getBodyWrapper: body => body,
+ emptyText: () => 'No Data',
+};
- getInitialState() {
- const props = this.props;
- let expandedRowKeys = [];
- let rows = [...props.data];
- this.columnManager = new ColumnManager(props.columns, props.children);
- this.store = createStore({ currentHoverKey: null });
+class Table extends Component{
+ constructor(props){
+ super(props);
+ let expandedRowKeys = [];
+ let rows = [...props.data];
+ this.columnManager = new ColumnManager(props.columns, props.children);
+ this.store = createStore({ currentHoverKey: null });
- if (props.defaultExpandAllRows) {
- for (let i = 0; i < rows.length; i++) {
- const row = rows[i];
- expandedRowKeys.push(this.getRowKey(row, i));
- rows = rows.concat(row[props.childrenColumnName] || []);
+ if (props.defaultExpandAllRows) {
+ for (let i = 0; i < rows.length; i++) {
+ const row = rows[i];
+ expandedRowKeys.push(this.getRowKey(row, i));
+ rows = rows.concat(row[props.childrenColumnName] || []);
+ }
+ } else {
+ expandedRowKeys = props.expandedRowKeys || props.defaultExpandedRowKeys;
}
- } else {
- expandedRowKeys = props.expandedRowKeys || props.defaultExpandedRowKeys;
- }
- return {
- expandedRowKeys,
- data: props.data,
- currentHoverKey: null,
- scrollPosition: 'left',
- fixedColumnsHeadRowsHeight: [],
- fixedColumnsBodyRowsHeight: [],
- };
- },
+ this.state = {
+ expandedRowKeys,
+ data: props.data,
+ currentHoverKey: null,
+ scrollPosition: 'left',
+ fixedColumnsHeadRowsHeight: [],
+ fixedColumnsBodyRowsHeight: [],
+ }
+
+ this.onExpandedRowsChange = this.onExpandedRowsChange.bind(this);
+ this.onExpanded = this.onExpanded.bind(this);
+ this.onRowDestroy = this.onRowDestroy.bind(this);
+ this.getRowKey = this.getRowKey.bind(this);
+ this.getExpandedRows = this.getExpandedRows.bind(this);
+ this.getHeader = this.getHeader.bind(this);
+ this.getHeaderRows = this.getHeaderRows.bind(this);
+ this.getExpandedRow = this.getExpandedRow.bind(this);
+ this.getRowsByData = this.getRowsByData.bind(this);
+ this.getRows = this.getRows.bind(this);
+ this.getColGroup = this.getColGroup.bind(this);
+ this.getLeftFixedTable = this.getLeftFixedTable.bind(this);
+ this.getRightFixedTable = this.getRightFixedTable.bind(this);
+ this.getTable = this.getTable.bind(this);
+ this.getTitle = this.getTitle.bind(this);
+ this.getFooter = this.getFooter.bind(this);
+ this.getEmptyText = this.getEmptyText.bind(this);
+ this.getHeaderRowStyle = this.getHeaderRowStyle.bind(this);
+ this.syncFixedTableRowHeight = this.syncFixedTableRowHeight.bind(this);
+ this.resetScrollY = this.resetScrollY.bind(this);
+ this.findExpandedRow = this.findExpandedRow.bind(this);
+ this.isRowExpanded = this.isRowExpanded.bind(this);
+ this.detectScrollTarget = this.detectScrollTarget.bind(this);
+ this.handleBodyScroll = this.handleBodyScroll.bind(this);
+ this.handleRowHover = this.handleRowHover.bind(this);
+
+ }
componentDidMount() {
this.resetScrollY();
@@ -101,7 +128,7 @@ const Table = React.createClass({
window, 'resize', debounce(this.syncFixedTableRowHeight, 150)
);
}
- },
+ }
componentWillReceiveProps(nextProps) {
if ('data' in nextProps) {
@@ -122,24 +149,24 @@ const Table = React.createClass({
} else if (nextProps.children !== this.props.children) {
this.columnManager.reset(null, nextProps.children);
}
- },
+ }
componentDidUpdate() {
this.syncFixedTableRowHeight();
- },
+ }
componentWillUnmount() {
if (this.resizeEvent) {
this.resizeEvent.remove();
}
- },
+ }
onExpandedRowsChange(expandedRowKeys) {
if (!this.props.expandedRowKeys) {
this.setState({ expandedRowKeys });
}
this.props.onExpandedRowsChange(expandedRowKeys);
- },
+ }
onExpanded(expanded, record, e, index) {
if (e) {
@@ -155,7 +182,7 @@ const Table = React.createClass({
this.onExpandedRowsChange(expandedRows);
}
this.props.onExpand(expanded, record);
- },
+ }
onRowDestroy(record, rowIndex) {
const expandedRows = this.getExpandedRows().concat();
@@ -170,7 +197,7 @@ const Table = React.createClass({
expandedRows.splice(index, 1);
}
this.onExpandedRowsChange(expandedRows);
- },
+ }
getRowKey(record, index) {
const rowKey = this.props.rowKey;
@@ -182,20 +209,20 @@ const Table = React.createClass({
'or set `rowKey` to an unique primary key.'
);
return key;
- },
+ }
getExpandedRows() {
return this.props.expandedRowKeys || this.state.expandedRowKeys;
- },
+ }
getHeader(columns, fixed) {
- const { showHeader, expandIconAsCell, prefixCls } = this.props;
+ const { showHeader, expandIconAsCell, clsPrefix } = this.props;
const rows = this.getHeaderRows(columns);
if (expandIconAsCell && fixed !== 'right') {
rows[0].unshift({
key: 'rc-table-expandIconAsCell',
- className: `${prefixCls}-expand-icon-th`,
+ className: `${clsPrefix}-expand-icon-th`,
title: '',
rowSpan: rows.length,
});
@@ -205,12 +232,12 @@ const Table = React.createClass({
return showHeader ? (
) : null;
- },
+ }
getHeaderRows(columns, currentRow = 0, rows) {
rows = rows || [];
@@ -241,10 +268,10 @@ const Table = React.createClass({
}
});
return rows.filter(row => row.length > 0);
- },
+ }
getExpandedRow(key, content, visible, className, fixed) {
- const { prefixCls, expandIconAsCell } = this.props;
+ const { clsPrefix, expandIconAsCell } = this.props;
let colCount;
if (fixed === 'left') {
colCount = this.columnManager.leftLeafColumns().length;
@@ -274,13 +301,13 @@ const Table = React.createClass({
visible={visible}
className={className}
key={`${key}-extra-row`}
- prefixCls={`${prefixCls}-expanded-row`}
+ clsPrefix={`${clsPrefix}-expanded-row`}
indent={1}
expandable={false}
store={this.store}
/>
);
- },
+ }
getRowsByData(data, visible, indent, columns, fixed) {
const props = this.props;
@@ -343,7 +370,7 @@ const Table = React.createClass({
onExpand={this.onExpanded}
expandable={childrenColumn || expandedRowRender}
expanded={isRowExpanded}
- prefixCls={`${props.prefixCls}-row`}
+ clsPrefix={`${props.clsPrefix}-row`}
childrenColumnName={childrenColumnName}
columns={leafColumns}
expandIconColumnIndex={expandIconColumnIndex}
@@ -372,18 +399,18 @@ const Table = React.createClass({
}
}
return rst;
- },
+ }
getRows(columns, fixed) {
return this.getRowsByData(this.state.data, true, 0, columns, fixed);
- },
+ }
getColGroup(columns, fixed) {
let cols = [];
if (this.props.expandIconAsCell && fixed !== 'right') {
cols.push(
);
@@ -400,32 +427,32 @@ const Table = React.createClass({
return ;
}));
return {cols};
- },
+ }
getLeftFixedTable() {
return this.getTable({
columns: this.columnManager.leftColumns(),
fixed: 'left',
});
- },
+ }
getRightFixedTable() {
return this.getTable({
columns: this.columnManager.rightColumns(),
fixed: 'right',
});
- },
+ }
getTable(options = {}) {
const { columns, fixed } = options;
- const { prefixCls, scroll = {}, getBodyWrapper } = this.props;
+ const { clsPrefix, scroll = {}, getBodyWrapper } = this.props;
let { useFixedHeader } = this.props;
const bodyStyle = { ...this.props.bodyStyle };
const headStyle = {};
let tableClassName = '';
if (scroll.x || fixed) {
- tableClassName = `${prefixCls}-fixed`;
+ tableClassName = `${clsPrefix}-fixed`;
bodyStyle.overflowX = bodyStyle.overflowX || 'auto';
}
@@ -459,7 +486,7 @@ const Table = React.createClass({
}
}
const tableBody = hasBody ? getBodyWrapper(
-
+
{this.getRows(columns, fixed)}
) : null;
@@ -477,7 +504,7 @@ const Table = React.createClass({
if (useFixedHeader) {
headTable = (
{headTable}{BodyTable};
- },
+ }
getTitle() {
- const { title, prefixCls } = this.props;
+ const { title, clsPrefix } = this.props;
return title ? (
-
+
{title(this.state.data)}
) : null;
- },
+ }
getFooter() {
- const { footer, prefixCls } = this.props;
+ const { footer, clsPrefix } = this.props;
return footer ? (
-
+
{footer(this.state.data)}
) : null;
- },
+ }
getEmptyText() {
- const { emptyText, prefixCls, data } = this.props;
+ const { emptyText, clsPrefix, data } = this.props;
return !data.length ? (
-
+
{emptyText()}
) : null;
- },
+ }
getHeaderRowStyle(columns, rows) {
const { fixedColumnsHeadRowsHeight } = this.state;
@@ -569,14 +596,14 @@ const Table = React.createClass({
return { height: headerHeight / rows.length };
}
return null;
- },
+ }
syncFixedTableRowHeight() {
- const { prefixCls } = this.props;
+ const { clsPrefix } = this.props;
const headRows = this.refs.headTable ?
this.refs.headTable.querySelectorAll('thead') :
this.refs.bodyTable.querySelectorAll('thead');
- const bodyRows = this.refs.bodyTable.querySelectorAll(`.${prefixCls}-row`) || [];
+ const bodyRows = this.refs.bodyTable.querySelectorAll(`.${clsPrefix}-row`) || [];
const fixedColumnsHeadRowsHeight = [].map.call(
headRows, row => row.getBoundingClientRect().height || 'auto'
);
@@ -591,7 +618,7 @@ const Table = React.createClass({
fixedColumnsHeadRowsHeight,
fixedColumnsBodyRowsHeight,
});
- },
+ }
resetScrollY() {
if (this.refs.headTable) {
@@ -600,22 +627,22 @@ const Table = React.createClass({
if (this.refs.bodyTable) {
this.refs.bodyTable.scrollLeft = 0;
}
- },
+ }
findExpandedRow(record, index) {
const rows = this.getExpandedRows().filter(i => i === this.getRowKey(record, index));
return rows[0];
- },
+ }
isRowExpanded(record, index) {
return typeof this.findExpandedRow(record, index) !== 'undefined';
- },
+ }
detectScrollTarget(e) {
if (this.scrollTarget !== e.currentTarget) {
this.scrollTarget = e.currentTarget;
}
- },
+ }
handleBodyScroll(e) {
// Prevent scrollTop setter trigger onScroll event
@@ -654,26 +681,26 @@ const Table = React.createClass({
}
// Remember last scrollLeft for scroll direction detecting.
this.lastScrollLeft = e.target.scrollLeft;
- },
+ }
handleRowHover(isHover, key) {
this.store.setState({
currentHoverKey: isHover ? key : null,
});
- },
+ }
render() {
const props = this.props;
- const prefixCls = props.prefixCls;
+ const clsPrefix = props.clsPrefix;
- let className = props.prefixCls;
+ let className = props.clsPrefix;
if (props.className) {
className += ` ${props.className}`;
}
if (props.useFixedHeader || (props.scroll && props.scroll.y)) {
- className += ` ${prefixCls}-fixed-header`;
+ className += ` ${clsPrefix}-fixed-header`;
}
- className += ` ${prefixCls}-scroll-position-${this.state.scrollPosition}`;
+ className += ` ${clsPrefix}-scroll-position-${this.state.scrollPosition}`;
const isTableScroll = this.columnManager.isAnyColumnsFixed() ||
props.scroll.x ||
@@ -682,24 +709,27 @@ const Table = React.createClass({
return (
{this.getTitle()}
-
+
{this.columnManager.isAnyColumnsLeftFixed() &&
-
+
{this.getLeftFixedTable()}
}
-
+
{this.getTable({ columns: this.columnManager.groupedColumns() })}
{this.getEmptyText()}
{this.getFooter()}
{this.columnManager.isAnyColumnsRightFixed() &&
-
+
{this.getRightFixedTable()}
}
);
- },
-});
+ }
+};
+
+Table.propTypes = propTypes;
+Table.defaultProps = defaultProps;
export default Table;
diff --git a/src/TableCell.jsx b/src/TableCell.js
similarity index 74%
rename from src/TableCell.jsx
rename to src/TableCell.js
index 37b0f4f..eedeac0 100644
--- a/src/TableCell.jsx
+++ b/src/TableCell.js
@@ -1,28 +1,34 @@
-import React, { PropTypes } from 'react';
+import React, { PropTypes, Component } from 'react';
import objectPath from 'object-path';
-const TableCell = React.createClass({
- propTypes: {
+const propTypes = {
record: PropTypes.object,
- prefixCls: PropTypes.string,
+ clsPrefix: PropTypes.string,
index: PropTypes.number,
indent: PropTypes.number,
indentSize: PropTypes.number,
column: PropTypes.object,
- expandIcon: PropTypes.node,
- },
+ expandIcon: PropTypes.node
+};
+
+class TableCell extends Component{
+ constructor(props){
+ super(props);
+ this.isInvalidRenderCellText = this.isInvalidRenderCellText.bind(this);
+ this.handleClick = this.handleClick.bind(this);
+ }
isInvalidRenderCellText(text) {
return text && !React.isValidElement(text) &&
Object.prototype.toString.call(text) === '[object Object]';
- },
+ }
handleClick(e) {
const { record, column: { onCellClick } } = this.props;
if (onCellClick) {
onCellClick(record, e);
}
- },
+ }
render() {
- const { record, indentSize, prefixCls, indent,
+ const { record, indentSize, clsPrefix, indent,
index, expandIcon, column } = this.props;
const { dataIndex, render, className = '' } = column;
@@ -41,7 +47,7 @@ const TableCell = React.createClass({
}
}
- // Fix https://github.com/ant-design/ant-design/issues/1202
+
if (this.isInvalidRenderCellText(text)) {
text = null;
}
@@ -49,7 +55,7 @@ const TableCell = React.createClass({
const indentText = expandIcon ? (
) : null;
@@ -68,7 +74,9 @@ const TableCell = React.createClass({
{text}
);
- },
-});
+ }
+};
+
+TableCell.propTypes = propTypes;
export default TableCell;
diff --git a/src/TableHeader.jsx b/src/TableHeader.js
similarity index 54%
rename from src/TableHeader.jsx
rename to src/TableHeader.js
index 4a6ca8d..ecfda62 100644
--- a/src/TableHeader.jsx
+++ b/src/TableHeader.js
@@ -1,19 +1,23 @@
-import React, { PropTypes } from 'react';
+import React, { PropTypes, Component } from 'react';
import shallowequal from 'shallowequal';
-export default React.createClass({
- propTypes: {
- prefixCls: PropTypes.string,
+const propTypes = {
+ clsPrefix: PropTypes.string,
rowStyle: PropTypes.object,
rows: PropTypes.array,
- },
+}
+
+class TableHeader extends Component{
+ constructor(props){
+ super(props);
+ }
shouldComponentUpdate(nextProps) {
return !shallowequal(nextProps, this.props);
- },
+ }
render() {
- const { prefixCls, rowStyle, rows } = this.props;
+ const { clsPrefix, rowStyle, rows } = this.props;
return (
-
+
{
rows.map((row, index) => (
@@ -23,5 +27,9 @@ export default React.createClass({
}
);
- },
-});
+ }
+};
+
+TableHeader.propTypes = propTypes;
+
+export default TableHeader;
diff --git a/src/TableRow.jsx b/src/TableRow.js
similarity index 77%
rename from src/TableRow.jsx
rename to src/TableRow.js
index 781d08b..13f9da6 100644
--- a/src/TableRow.jsx
+++ b/src/TableRow.js
@@ -1,14 +1,13 @@
-import React, { PropTypes } from 'react';
+import React, { PropTypes, Component } from 'react';
import TableCell from './TableCell';
import ExpandIcon from './ExpandIcon';
-const TableRow = React.createClass({
- propTypes: {
+const propTypes = {
onDestroy: PropTypes.func,
onRowClick: PropTypes.func,
onRowDoubleClick: PropTypes.func,
record: PropTypes.object,
- prefixCls: PropTypes.string,
+ clsPrefix: PropTypes.string,
expandIconColumnIndex: PropTypes.number,
onHover: PropTypes.func,
columns: PropTypes.array,
@@ -29,24 +28,30 @@ const TableRow = React.createClass({
expandIconAsCell: PropTypes.bool,
expandRowByClick: PropTypes.bool,
store: PropTypes.object.isRequired,
- },
+};
- getDefaultProps() {
- return {
- onRowClick() {},
- onRowDoubleClick() {},
- onDestroy() {},
- expandIconColumnIndex: 0,
- expandRowByClick: false,
- onHover() {},
- };
- },
+const defaultProps = {
+ onRowClick() {},
+ onRowDoubleClick() {},
+ onDestroy() {},
+ expandIconColumnIndex: 0,
+ expandRowByClick: false,
+ onHover() {},
+};
+
+class TableRow extends Component{
+ constructor(props){
+ super(props);
+ this.state = {
+ hovered: false,
+ };
+ this.onRowClick = this.onRowClick.bind(this);
+ this.onRowDoubleClick = this.onRowDoubleClick.bind(this);
+ this.onMouseEnter = this.onMouseEnter.bind(this);
+ this.onMouseLeave = this.onMouseLeave.bind(this);
+
+ }
- getInitialState() {
- return {
- hovered: false,
- };
- },
componentDidMount() {
const { store, hoverKey } = this.props;
@@ -57,7 +62,7 @@ const TableRow = React.createClass({
this.setState({ hovered: false });
}
});
- },
+ }
componentWillUnmount() {
const { record, onDestroy, index } = this.props;
@@ -65,7 +70,7 @@ const TableRow = React.createClass({
if (this.unsubscribe) {
this.unsubscribe();
}
- },
+ }
onRowClick(event) {
const {
@@ -81,26 +86,26 @@ const TableRow = React.createClass({
onExpand(!expanded, record, index);
}
onRowClick(record, index, event);
- },
+ }
onRowDoubleClick(event) {
const { record, index, onRowDoubleClick } = this.props;
onRowDoubleClick(record, index, event);
- },
+ }
onMouseEnter() {
const { onHover, hoverKey } = this.props;
onHover(true, hoverKey);
- },
+ }
onMouseLeave() {
const { onHover, hoverKey } = this.props;
onHover(false, hoverKey);
- },
+ }
render() {
const {
- prefixCls, columns, record, height, visible, index,
+ clsPrefix, columns, record, height, visible, index,
expandIconColumnIndex, expandIconAsCell, expanded, expandRowByClick,
expandable, onExpand, needIndentSpaced, indent, indentSize,
} = this.props;
@@ -108,7 +113,7 @@ const TableRow = React.createClass({
let { className } = this.props;
if (this.state.hovered) {
- className += ` ${prefixCls}-hover`;
+ className += ` ${clsPrefix}-hover`;
}
const cells = [];
@@ -116,7 +121,7 @@ const TableRow = React.createClass({
const expandIcon = (
{expandIcon}
@@ -139,7 +144,7 @@ const TableRow = React.createClass({
? false : (i === expandIconColumnIndex);
cells.push(
{cells}
);
- },
-});
+ }
+};
+
+TableRow.propTypes = propTypes;
+TableRow.defaultProps = defaultProps;
export default TableRow;
diff --git a/src/animation.scss b/src/animation.scss
deleted file mode 100644
index a6d4e92..0000000
--- a/src/animation.scss
+++ /dev/null
@@ -1,59 +0,0 @@
-
-.move-enter, .move-appear {
- opacity: 0;
- animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
- animation-duration: 2.5s;
- animation-fill-mode: both;
- animation-play-state: paused;
-}
-
-.move-leave {
- animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
- animation-duration: .5s;
- animation-fill-mode: both;
- animation-play-state: paused;
-}
-
-.move-enter.move-enter-active, .move-appear.move-enter-active {
- animation-name: moveLeftIn;
- animation-play-state: running;
-}
-
-.move-leave.move-leave-active {
- animation-name: moveRightOut;
- animation-play-state: running;
-}
-
-@keyframes moveLeftIn {
- 0% {
- transform-origin: 0 0;
- transform: translateX(30px);
- opacity: 0;
- background: #fff6de;
- }
- 20% {
- transform-origin: 0 0;
- transform: translateX(0);
- opacity: 1;
- }
- 80%{
- background: #fff6de;
- }
- 100%{
- background: transparent;
- opacity: 1;
- }
-}
-
-@keyframes moveRightOut {
- 0% {
- transform-origin: 0 0;
- transform: translateX(0);
- opacity: 1;
- }
- 100% {
- transform-origin: 0 0;
- transform: translateX(-30px);
- opacity: 0;
- }
-}
diff --git a/src/bordered.scss b/src/bordered.scss
deleted file mode 100644
index b27b99d..0000000
--- a/src/bordered.scss
+++ /dev/null
@@ -1,11 +0,0 @@
-
-$table-border-color: #e9e9e9;
-
-.u-table.bordered {
- table {
- border-collapse: collapse;
- }
- th, td {
- border: 1px solid $table-border-color;
- }
-}
diff --git a/src/index.scss b/src/index.scss
index 6371699..2a49ea9 100644
--- a/src/index.scss
+++ b/src/index.scss
@@ -2,10 +2,16 @@
$text-color : #666;
$font-size-base : 12px;
$line-height: 1.5;
-$table-border-color: #e9e9e9;
+$table-border-color: $border-color-base;
$table-head-background-color: #f7f7f7;
$vertical-padding: 16px;
$horizontal-padding: 8px;
+$table-border-color: #e9e9e9;
+
+$table-hover-color: unquote("rgb(#{$palette-blue-50})") !default;
+$table-move-in-color: $bg-color-base;
+
+
.u-table {
font-size: $font-size-base;
@@ -15,6 +21,38 @@ $horizontal-padding: 8px;
line-height: $line-height;
overflow: hidden;
+ table {
+ width: 100%;
+ border-collapse: collapse;
+ text-align: left;
+ }
+
+ th {
+ background: $table-head-background-color;
+ font-weight: bold;
+ transition: background .3s ease;
+ }
+
+ td {
+ border-bottom: 1px solid $table-border-color;
+ }
+
+ tr {
+ transition: all .3s ease;
+ &:hover {
+ background: $table-hover-color;
+ }
+
+ }
+ tr.tr-row-hover {
+ background: $table-hover-color;
+ }
+
+ th, td {
+ padding: $vertical-padding $horizontal-padding;
+ }
+
+
&-scroll {
overflow: auto;
}
@@ -64,39 +102,6 @@ $horizontal-padding: 8px;
position: relative;
}
- table {
- width: 100%;
- border-collapse: separate;
- text-align: left;
- }
-
- th {
- background: $table-head-background-color;
- font-weight: bold;
- transition: background .3s ease;
- }
-
- td {
- border-bottom: 1px solid $table-border-color;
- }
-
- tr {
- transition: all .3s ease;
- &:hover {
- background: #eaf8fe;
- }
-
- }
- tr.tr-row-hover {
- background: #eaf8fe;
- }
-
- th, td {
- padding: $vertical-padding $horizontal-padding;
- }
-}
-
-.u-table {
&-expand-icon-col {
width: 10px;
}
@@ -209,3 +214,75 @@ $horizontal-padding: 8px;
box-shadow: none;
}
}
+
+
+
+
+.u-table.bordered {
+ table {
+ border-collapse: collapse;
+ }
+ th, td {
+ border: 1px solid $table-border-color;
+ }
+}
+
+
+.move-enter, .move-appear {
+ opacity: 0;
+ animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
+ animation-duration: 2.5s;
+ animation-fill-mode: both;
+ animation-play-state: paused;
+}
+
+.move-leave {
+ animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
+ animation-duration: .5s;
+ animation-fill-mode: both;
+ animation-play-state: paused;
+}
+
+.move-enter.move-enter-active, .move-appear.move-enter-active {
+ animation-name: moveLeftIn;
+ animation-play-state: running;
+}
+
+.move-leave.move-leave-active {
+ animation-name: moveRightOut;
+ animation-play-state: running;
+}
+
+@keyframes moveLeftIn {
+ 0% {
+ transform-origin: 0 0;
+ transform: translateX(30px);
+ opacity: 0;
+ background: $table-move-in-color;
+ }
+ 20% {
+ transform-origin: 0 0;
+ transform: translateX(0);
+ opacity: 1;
+ }
+ 80%{
+ background: $table-move-in-color;
+ }
+ 100%{
+ background: transparent;
+ opacity: 1;
+ }
+}
+
+@keyframes moveRightOut {
+ 0% {
+ transform-origin: 0 0;
+ transform: translateX(0);
+ opacity: 1;
+ }
+ 100% {
+ transform-origin: 0 0;
+ transform: translateX(-30px);
+ opacity: 0;
+ }
+}