@gmfe/table-x 2.13.0-beta.2 → 2.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmfe/table-x",
3
- "version": "2.13.0-beta.2",
3
+ "version": "2.13.1",
4
4
  "description": "",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gmfe#readme",
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@gm-common/tool": "^1.0.0",
30
- "@gmfe/locales": "^2.13.0-beta.2",
31
- "@gmfe/react": "^2.13.0-beta.2",
30
+ "@gmfe/locales": "^2.13.1",
31
+ "@gmfe/react": "^2.13.1",
32
32
  "classnames": "^2.2.5",
33
33
  "lodash": "^4.17.14",
34
34
  "prop-types": "^15.7.2",
@@ -36,5 +36,5 @@
36
36
  "react-window": "^1.8.5",
37
37
  "sortablejs": "^1.10.1"
38
38
  },
39
- "gitHead": "fd3a8e87722bfa50b2d82a37f938b619a86987cf"
39
+ "gitHead": "5fe17bc2d89949e39d7a9eeca34b7c991cb01337"
40
40
  }
@@ -2,6 +2,7 @@ import React, { useEffect } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import TableX from '../base'
4
4
  import SortableJS from 'sortablejs'
5
+ import _ from 'lodash'
5
6
 
6
7
  function sortableTableX(Component) {
7
8
  const SortableTableX = ({ id, data, onSortChange, keyField, ...rest }) => {
@@ -15,21 +16,16 @@ function sortableTableX(Component) {
15
16
  onStart: () => {
16
17
  target.classList.add('gm-table-x-sortable-active')
17
18
  },
18
- onEnd: ({ newIndex, oldIndex }) => {
19
+ onEnd: () => {
19
20
  target.classList.remove('gm-table-x-sortable-active')
20
- // 删除原本位置的数据
21
- const deleteData = data.splice(oldIndex, 1)
22
- // 将删除的数据添加到新的位置
23
- data.splice(newIndex, 0, deleteData[0])
24
- onSortChange(data)
21
+ },
22
+ onUpdate: evt => {
23
+ const newIds = sortable.toArray()
24
+ const newData = _.sortBy(data.slice(), v =>
25
+ newIds.indexOf(v[keyField])
26
+ )
27
+ onSortChange(newData)
25
28
  }
26
- // onUpdate: evt => {
27
- // const newIds = sortable.toArray()
28
- // const newData = _.sortBy(data.slice(), v => {
29
- // return newIds.indexOf(v[keyField]) // 返回位置
30
- // })
31
- // onSortChange(newData)
32
- // }
33
29
  })
34
30
 
35
31
  return () => {
@@ -165,7 +165,7 @@ const columns = [
165
165
  accessor: 'index',
166
166
  fixed: 'left',
167
167
  width: TABLE_X.WIDTH_NO,
168
- Cell: ({ row }) => {return row.index + 1}
168
+ Cell: ({ row }) => row.index + 1
169
169
  },
170
170
  // 常规用法
171
171
  {
@@ -396,8 +396,7 @@ storiesOf('TableX|HOC', module)
396
396
  keyField='id'
397
397
  onSortChange={newData => {
398
398
  console.log(newData.map(v => v.id))
399
- // 不需要将newData重新赋值给data
400
- // store.setData(newData)
399
+ store.setData(newData)
401
400
  }}
402
401
  />
403
402
  ))