MCPcopy Create free account
hub / github.com/Autodesk/react-base-table / DraggableTable

Class DraggableTable

website/src/examples/draggable-rows.js:41–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39})
40
41class DraggableTable extends React.PureComponent {
42 state = {
43 data: this.props.data,
44 }
45
46 table = React.createRef()
47
48 getContainer = () => {
49 return this.table.current.getDOMNode().querySelector('.BaseTable__body')
50 }
51
52 getHelperContainer = () => {
53 return this.table.current.getDOMNode().querySelector('.BaseTable__table')
54 }
55
56 rowProps = args => {
57 // don't forget to passing the incoming rowProps
58 const extraProps = callOrReturn(this.props.rowProps)
59 return {
60 ...extraProps,
61 tagName: Row,
62 index: args.rowIndex,
63 }
64 }
65
66 handleSortEnd = ({ oldIndex, newIndex }) => {
67 const data = [...this.state.data]
68 const [removed] = data.splice(oldIndex, 1)
69 data.splice(newIndex, 0, removed)
70 this.setState({ data })
71 }
72
73 render() {
74 return (
75 <DraggableContainer
76 useDragHandle
77 getContainer={this.getContainer}
78 helperContainer={this.getHelperContainer}
79 onSortEnd={this.handleSortEnd}
80 >
81 <Table
82 {...this.props}
83 ref={this.table}
84 data={this.state.data}
85 fixed={false}
86 rowProps={this.rowProps}
87 />
88 </DraggableContainer>
89 )
90 }
91}
92
93const Hint = styled.div`
94 font-size: 16px;

Callers

nothing calls this directly

Calls 2

callOrReturnFunction · 0.85
getDOMNodeMethod · 0.80

Tested by

no test coverage detected