1.5.33 • Published 3 months ago

@eatong/reactable v1.5.33

Weekly downloads
28
License
-
Repository
github
Last release
3 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.5.33

3 months ago

1.5.32

6 months ago

1.5.31

1 year ago

1.5.30

2 years ago

1.7.3

3 years ago

1.5.29

3 years ago

1.5.28

3 years ago

1.5.27

3 years ago

1.5.26

3 years ago

1.5.25

3 years ago

1.5.23

3 years ago

1.5.24

3 years ago

1.5.22

3 years ago

1.5.21

3 years ago

1.5.19

3 years ago

1.5.20

3 years ago

1.5.18

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.5.17

4 years ago

1.6.9

4 years ago

1.6.11

4 years ago

1.6.10

4 years ago

1.6.12

4 years ago

1.6.8

4 years ago

1.6.7

4 years ago

1.6.6

4 years ago

1.6.5

4 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.6.0-beta1

4 years ago

1.5.16

4 years ago

1.5.15

4 years ago

1.5.14

4 years ago

1.5.13

4 years ago

1.5.12

4 years ago

1.5.11

4 years ago

1.5.10

4 years ago

1.5.9

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.5

4 years ago

1.5.4

4 years ago

1.5.6

4 years ago

1.5.3

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.8

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.16.16

5 years ago

0.16.15

5 years ago

0.16.14

5 years ago

0.16.13

5 years ago

0.16.12

5 years ago

0.16.11

5 years ago

0.16.10

5 years ago

0.16.9

5 years ago

0.16.8

5 years ago

0.16.7

5 years ago

0.16.6

5 years ago

0.16.5

5 years ago

0.16.4

5 years ago

0.16.3

5 years ago

0.16.2

5 years ago

0.16.1

5 years ago

0.16.0

5 years ago

0.15.13

5 years ago

0.15.12

5 years ago

0.15.11

5 years ago

0.15.10

5 years ago

0.15.9

5 years ago

0.15.8

5 years ago

0.15.7

5 years ago

0.15.6

5 years ago

0.15.5

5 years ago

0.15.4

5 years ago

0.15.3

5 years ago

0.15.2

5 years ago

0.15.1

5 years ago

0.15.0

5 years ago

0.14.15

5 years ago

0.14.14

5 years ago

0.14.13

5 years ago

0.14.12

5 years ago

0.14.11

5 years ago

0.14.10

5 years ago

0.14.9

5 years ago

0.14.7

5 years ago

0.14.6

5 years ago

0.14.5

5 years ago

0.14.4

5 years ago

0.14.3

5 years ago

0.14.2

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.13

5 years ago

0.13.12

5 years ago

0.13.11

5 years ago

0.13.10

5 years ago

0.13.9

5 years ago

0.13.8

5 years ago

0.13.7

5 years ago

0.13.6

5 years ago

0.13.5

5 years ago

0.13.4

5 years ago

0.13.3

5 years ago

0.13.2

5 years ago

0.13.1

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.5

5 years ago

0.11.4

5 years ago

0.11.3

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.2

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago