@@ -8,7 +8,18 @@ const Handle = styled.div`
88 flex: none;
99 width: 7.5px;
1010 height: 100%;
11- background: #888;
11+
12+ &::before {
13+ content: '';
14+ border-left: 4px dotted #ccc;
15+ display: block;
16+ height: 20px;
17+ margin: 15px 3px;
18+ }
19+
20+ &:hover::before {
21+ border-color: #888
22+ }
1223`
1324
1425const Row = ( { key, index, children, ...rest } ) => (
@@ -28,6 +39,10 @@ const rowProps = ({ rowIndex }) => ({
2839} )
2940
3041class DraggableTable extends React . PureComponent {
42+ state = {
43+ data : this . props . data ,
44+ }
45+
3146 getContainer ( ) {
3247 return document . querySelector ( '.BaseTable__body' )
3348 }
@@ -46,14 +61,27 @@ class DraggableTable extends React.PureComponent {
4661 }
4762 }
4863
64+ handleSortEnd = ( { oldIndex, newIndex } ) => {
65+ const data = [ ...this . state . data ]
66+ const [ removed ] = data . splice ( oldIndex , 1 )
67+ data . splice ( newIndex , 0 , removed )
68+ this . setState ( { data } )
69+ }
70+
4971 render ( ) {
5072 return (
5173 < DraggableContainer
5274 useDragHandle
5375 getContainer = { this . getContainer }
5476 helperContainer = { this . getHelperContainer }
77+ onSortEnd = { this . handleSortEnd }
5578 >
56- < Table { ...this . props } fixed = { false } rowProps = { this . rowProps } />
79+ < Table
80+ { ...this . props }
81+ data = { this . state . data }
82+ fixed = { false }
83+ rowProps = { this . rowProps }
84+ />
5785 </ DraggableContainer >
5886 )
5987 }
@@ -68,10 +96,11 @@ const Hint = styled.div`
6896
6997const columns = generateColumns ( 10 )
7098const data = generateData ( columns , 200 )
99+ columns [ 0 ] . minWidth = 150
71100
72101export default ( ) => (
73102 < >
74- < Hint > Drag the gray handles , only works in flex mode(fixed=false)</ Hint >
103+ < Hint > Drag the dots , only works in flex mode(fixed=false)</ Hint >
75104 < DraggableTable columns = { columns } data = { data } />
76105 </ >
77106)
0 commit comments