1.7.22 • Published 11 months ago

@eatong/reactable v1.7.22

Weekly downloads
28
License
none
Repository
github
Last release
11 months ago

reactable

react table

NPM JavaScript Style Guide

Install

npm install --save @eatong/reactable

roadmap

  • basic table showing
  • header resizeable
  • fixed header
  • fixed columns
  • auto width
  • cached width
  • fixed column at right side
  • cell animation when value changed
  • row selection
  • effective edit
  • fixed footer row
  • child row
  • full row render
  • children header
  • custom row class
  • column column class
  • custom cell class
  • cell editable
  • row animation
  • disable row selection
  • keyboard navigation
  • pagination
  • hide column
  • column filter and column sort

Usage

import React, {Component} from 'react'
import 'antd/dist/antd.css';
import Reactable from 'reactable'

const columns = [
  {title: 'aaa', dataIndex: 'a', fixed: true},
  {title: 'bbbb', dataIndex: 'b', width: 200},
  {title: 'ccc', dataIndex: 'c', width: 'auto'},
  {title: 'ddd', dataIndex: 'd', width: 'auto', editRender: () => <input/>},
  {title: 'eee', dataIndex: 'e', width: '150', fixed: 'right'},
  {title: 'ffff', dataIndex: 'f', fixed: true}
];

export default class App extends Component {
  state = {
    dataSource: [
      {
        id: 1,
        a: '11111',
        b: '1b1b11',
        c: '1c1c1c1c11',
        d: '1d1d1d1d1d1d1d1d',
        e: '1e1e1e1e1e1ee1',
        children: [
          {id: `child-key-0`, a: '000000aaa', b: '0000bbb', c: '0000ccc', d: '000ddd', e: '000eee', f: 'fff'}
        ]
      },
      {
        id: 2,
        a: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa',
        b: 'bbbbbbb',
        c: 'cccccc',
        d: 'dddddd',
        e: 'eeeeeeeeeeeeeee',
        children: [
          {id: `child-key-1`, a: 'aaa', b: 'bbb', c: 'ccc', d: 'ddd', e: 'eee', f: 'fff'}
        ]
      },
      {id: 3, a: 'aasdf', b: '23234', c: 'asdfasfd', d: '333232333', e: '2323232'},
      {id: 4, a: 'eee', b: '234sdfw4rq2334q2342', c: 'aaaaa', d: '33333', e: 'aaaa'},
      {id: 5, a: 'fasd cv', b: 'asdfa243232323', c: '234243rwefdsars', d: '34ewerfdas', e: '234qrwaefsdasdf'},
      {id: 6, a: 'sdfasdf24rwfsd', b: 'asd2r13rt', c: '23rfgsterwq4r34', d: '234q2weafsdtg', e: 'asdrq12r3egsdf'}
    ]
  };

  componentWillMount() {
    setTimeout(() => {
      const {dataSource} = this.state;
      dataSource[0].a = 'dasfaslkdfjas;dlfjk';
      this.setState({dataSource: [...dataSource]});
      // this.setState({dataSource: [...this.state.dataSource, ...this.generateDataSource()]})
    }, 3000)
  }

  generateDataSource() {
    const dataSource = [];
    for (let i = 0; i < 100; i++) {
      dataSource.push(
        {
          id: 'key' + i,
          a: `aaaa:」${Math.random()}`,
          b: `bbbb:」${Math.random()}`,
          c: `c:」${Math.random()}`,
          d: `d:」${Math.random()}`,
          e: `e:」${Math.random()}`,
          children: [
            {id: `child-key-${0}`, a: 'aaa', b: 'bbb', c: 'ccc', d: 'ddd', e: 'eee', f: 'fff'}
          ]
        })
    }
    return dataSource;
  }

  render() {
    return (
      <div className={'reactable-test'}>
        <Reactable
          editMode
          columns={columns}
          dataSource={this.state.dataSource}
          onTableReady={table => this.table = table}
          getRowClass={(row, index) => index % 2 ? 'odd' : 'even'}
          getCellClass={(row, index, column) => index}
          rowSelection={{
            // type: 'radio',
            onChange: (a, b, c) => {
              console.log(a, b, c);
            }
          }}
          onChangeCell={(value, index, key) => this.table.updateCell(index + 1, 'c', value)}
        />

        <button onClick={() => {
          this.table.updateCell(1 + ~~(Math.random() * 6), 'a', Math.random());
          this.table.updateCell(1 + ~~(Math.random() * 6), 'b', Math.random());
          this.table.updateCell(1 + ~~(Math.random() * 6), 'c', Math.random());
          this.table.updateCell(1 + ~~(Math.random() * 6), 'd', Math.random());
          this.table.updateCell(1 + ~~(Math.random() * 6), 'e', Math.random());
        }}>
          update random cell value
        </button>
        <button onClick={() => this.table.updateRow(1, {a: 'new A', b: 'new b', c: 'new c', d: 'new d', e: 'new e'})}>
          update key 1
        </button>
        <button onClick={() => {
          this.table.addRows([{a: 1, b: 2, c: 3, d: 4, e: 5, id: Math.random()}], 0, {autoScroll: true});
        }}>
          add row
        </button>
        <button onClick={() => {
          this.table.addRows([{a: 1, b: 2, c: 3, d: 4, e: 5, id: Math.random()}], null, {autoScroll: true});
        }}>
          add row at end
        </button>
        <button onClick={() => {
          const data = {a: 1, b: 2, c: 3, d: 4, e: 5, id: Math.random()};
          const data2 = {a: 11, b: 22, c: 33, d: 44, e: 5, id: Math.random()};
          this.table.addRows([data, data2], ~~(Math.random() * this.table.getDataSource().length), {replace: true});
        }}>
          replace random row
        </button>
      </div>
    )
  }
}

License

MIT © eaTong

1.7.21

11 months ago

1.7.22

11 months ago

1.5.33

1 year ago

1.5.32

2 years ago

1.5.31

3 years ago

1.5.30

4 years ago

1.7.3

4 years ago

1.5.29

4 years ago

1.5.28

4 years ago

1.5.27

4 years ago

1.5.26

4 years ago

1.5.25

4 years ago

1.5.23

5 years ago

1.5.24

5 years ago

1.5.22

5 years ago

1.5.21

5 years ago

1.5.19

5 years ago

1.5.20

5 years ago

1.5.18

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.5.17

5 years ago

1.6.9

5 years ago

1.6.11

5 years ago

1.6.10

5 years ago

1.6.12

5 years ago

1.6.8

5 years ago

1.6.7

5 years ago

1.6.6

5 years ago

1.6.5

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.6.0-beta1

5 years ago

1.5.16

5 years ago

1.5.15

5 years ago

1.5.14

5 years ago

1.5.13

5 years ago

1.5.12

5 years ago

1.5.11

5 years ago

1.5.10

5 years ago

1.5.9

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.5.8

5 years ago

1.5.7

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.6

5 years ago

1.5.3

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.8

5 years ago

1.4.6

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.16.16

6 years ago

0.16.15

6 years ago

0.16.14

6 years ago

0.16.13

6 years ago

0.16.12

6 years ago

0.16.11

6 years ago

0.16.10

6 years ago

0.16.9

6 years ago

0.16.8

6 years ago

0.16.7

6 years ago

0.16.6

6 years ago

0.16.5

6 years ago

0.16.4

6 years ago

0.16.3

6 years ago

0.16.2

6 years ago

0.16.1

6 years ago

0.16.0

6 years ago

0.15.13

6 years ago

0.15.12

6 years ago

0.15.11

6 years ago

0.15.10

6 years ago

0.15.9

6 years ago

0.15.8

6 years ago

0.15.7

6 years ago

0.15.6

6 years ago

0.15.5

6 years ago

0.15.4

6 years ago

0.15.3

6 years ago

0.15.2

6 years ago

0.15.1

6 years ago

0.15.0

6 years ago

0.14.15

6 years ago

0.14.14

6 years ago

0.14.13

6 years ago

0.14.12

6 years ago

0.14.11

6 years ago

0.14.10

6 years ago

0.14.9

6 years ago

0.14.7

6 years ago

0.14.6

6 years ago

0.14.5

6 years ago

0.14.4

6 years ago

0.14.3

6 years ago

0.14.2

6 years ago

0.14.1

6 years ago

0.14.0

6 years ago

0.13.13

6 years ago

0.13.12

6 years ago

0.13.11

6 years ago

0.13.10

6 years ago

0.13.9

6 years ago

0.13.8

6 years ago

0.13.7

6 years ago

0.13.6

6 years ago

0.13.5

6 years ago

0.13.4

6 years ago

0.13.3

6 years ago

0.13.2

6 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.12.0

6 years ago

0.11.5

6 years ago

0.11.4

6 years ago

0.11.3

6 years ago

0.11.1

6 years ago

0.11.0

6 years ago

0.10.2

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago