MCPcopy Create free account
hub / github.com/Lobos/react-ui / Table

Class Table

src/Table.js:13–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11requireCss('tables');
12
13class Table extends Component {
14 constructor (props) {
15 super(props);
16 this.state = {
17 index: props.pagination ? props.pagination.props.index : 1,
18 data: props.data,
19 sort: {},
20 total: null
21 };
22
23 this.onBodyScroll = this.onBodyScroll.bind(this);
24 }
25
26 componentDidMount () {
27 this.setHeaderWidth();
28 }
29
30 componentWillReceiveProps (nextProps) {
31 if (!deepEqual(nextProps.data, this.props.data)) {
32 this.setState({ data: nextProps.data });
33 }
34 }
35
36 componentDidUpdate () {
37 this.setHeaderWidth();
38 }
39
40 checkHeadFixed () {
41 const { height } = this.props;
42 return !!height && height !== 'auto';
43 }
44
45 setHeaderWidth () {
46 if (!this.checkHeadFixed()) {
47 return;
48 }
49 let body = this.refs.body;
50 let tr = body.querySelector('tr');
51 if (!tr) {
52 return;
53 }
54
55 let ths = this.refs.header.querySelectorAll('th');
56
57 let tds = tr.querySelectorAll('td');
58 if (tds.length <= 1) {
59 return;
60 }
61 for (let i = 0, count = tds.length; i < count; i++) {
62 if (ths[i]) {
63 ths[i].style.width = tds[i].offsetWidth + 'px';
64 }
65 }
66 }
67
68 sortData (key, asc) {
69 let data = this.state.data;
70 data = data.sort(function(a, b) {

Callers

nothing calls this directly

Calls 2

sortDataMethod · 0.95
onSortMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…