Skip to content

Commit

Permalink
docs(table): upgrade react-sortable-hoc usage (#33729)
Browse files Browse the repository at this point in the history
Co-authored-by: 亦逊 <eason.ym@alibaba-inc.com>
  • Loading branch information
yanm1ng and 亦逊 committed Jan 14, 2022
1 parent f53e615 commit 54ef44b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions components/table/demo/drag-sorting-handler.md
Expand Up @@ -15,11 +15,11 @@ Alternatively you can implement drag sorting with handler using [react-sortable-

```jsx
import { Table } from 'antd';
import { sortableContainer, sortableElement, sortableHandle } from 'react-sortable-hoc';
import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';
import { MenuOutlined } from '@ant-design/icons';
import { arrayMoveImmutable } from 'array-move';

const DragHandle = sortableHandle(() => <MenuOutlined style={{ cursor: 'grab', color: '#999' }} />);
const DragHandle = SortableHandle(() => <MenuOutlined style={{ cursor: 'grab', color: '#999' }} />);

const columns = [
{
Expand Down Expand Up @@ -68,8 +68,8 @@ const data = [
},
];

const SortableItem = sortableElement(props => <tr {...props} />);
const SortableContainer = sortableContainer(props => <tbody {...props} />);
const SortableItem = SortableElement(props => <tr {...props} />);
const SortableBody = SortableContainer(props => <tbody {...props} />);

class SortableTable extends React.Component {
state = {
Expand All @@ -79,14 +79,16 @@ class SortableTable extends React.Component {
onSortEnd = ({ oldIndex, newIndex }) => {
const { dataSource } = this.state;
if (oldIndex !== newIndex) {
const newData = arrayMoveImmutable([].concat(dataSource), oldIndex, newIndex).filter(el => !!el);
const newData = arrayMoveImmutable([].concat(dataSource), oldIndex, newIndex).filter(
el => !!el,
);
console.log('Sorted items: ', newData);
this.setState({ dataSource: newData });
}
};

DraggableContainer = props => (
<SortableContainer
<SortableBody
useDragHandle
disableAutoscroll
helperClass="row-dragging"
Expand Down

0 comments on commit 54ef44b

Please sign in to comment.