vxe-table 3.8.5 → 3.8.6-beta.0

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.
@@ -567,12 +567,21 @@ const Methods = {
567
567
  return this.loadColumn(columns)
568
568
  })
569
569
  },
570
+ initColumnSort () {
571
+ const { collectColumn } = this
572
+ collectColumn.forEach((column, index) => {
573
+ const sortIndex = index + 1
574
+ column.sortNumber = sortIndex
575
+ column.renderSortNumber = sortIndex
576
+ })
577
+ },
570
578
  handleColumn (collectColumn) {
571
579
  this.collectColumn = collectColumn
572
580
  const tableFullColumn = getColumnList(collectColumn)
573
581
  this.tableFullColumn = tableFullColumn
574
- this.cacheColumnMap(true)
582
+ this.initColumnSort()
575
583
  this.restoreCustomStorage()
584
+ this.cacheColumnMap()
576
585
  this.parseColumns().then(() => {
577
586
  if (this.scrollXLoad) {
578
587
  this.loadScrollXData(true)
@@ -699,7 +708,7 @@ const Methods = {
699
708
  * 更新数据列的 Map
700
709
  * 牺牲数据组装的耗时,用来换取使用过程中的流畅
701
710
  */
702
- cacheColumnMap (isInit) {
711
+ cacheColumnMap () {
703
712
  const { tableFullColumn, collectColumn, fullColumnMap, showOverflow, columnOpts, rowOpts } = this
704
713
  const fullColumnIdData = this.fullColumnIdData = {}
705
714
  const fullColumnFieldData = this.fullColumnFieldData = {}
@@ -795,9 +804,6 @@ const Methods = {
795
804
  if (fullColumnIdData[colid]) {
796
805
  errLog('vxe.error.colRepet', ['colId', colid])
797
806
  }
798
- if (isInit) {
799
- column.sortNumber = index
800
- }
801
807
  fullColumnIdData[colid] = rest
802
808
  fullColumnMap.set(column, rest)
803
809
  }
@@ -1575,6 +1581,9 @@ const Methods = {
1575
1581
  if (opts.resizable) {
1576
1582
  this.saveCustomResizable(true)
1577
1583
  }
1584
+ if (opts.sort) {
1585
+ this.saveCustomSort(true)
1586
+ }
1578
1587
  if (opts.fixed) {
1579
1588
  this.saveCustomFixed()
1580
1589
  }
@@ -1592,6 +1601,7 @@ const Methods = {
1592
1601
  }
1593
1602
  }
1594
1603
  this.saveCustomVisible()
1604
+ this.saveCustomSort()
1595
1605
  this.analyColumnWidth()
1596
1606
  return this.refreshColumn(true)
1597
1607
  },
@@ -1599,7 +1609,7 @@ const Methods = {
1599
1609
  * 还原自定义列操作状态
1600
1610
  */
1601
1611
  restoreCustomStorage () {
1602
- const { id, collectColumn, customConfig, customOpts } = this
1612
+ const { id, customConfig, customOpts } = this
1603
1613
  const { storage } = customOpts
1604
1614
  const isAllStorage = storage === true
1605
1615
  const storageOpts = isAllStorage ? {} : Object.assign({}, storage || {})
@@ -1637,16 +1647,18 @@ const Methods = {
1637
1647
  }
1638
1648
  }
1639
1649
  // 自定义顺序
1650
+ let hasCustomSort = false
1640
1651
  if (isCustomSort) {
1641
1652
  const columnSortStorage = getCustomStorageMap(sortStorageKey)[id]
1642
1653
  if (columnSortStorage) {
1643
- const colOrderSeqs = columnSortStorage.split(',')
1644
- colOrderSeqs.forEach((orderConf) => {
1645
- const [colKey, sortNumber] = orderConf.split('|')
1654
+ XEUtils.each(columnSortStorage, (renderSortNumber, colKey) => {
1646
1655
  if (customMap[colKey]) {
1647
- customMap[colKey].sortNumber = sortNumber
1656
+ customMap[colKey].renderSortNumber = renderSortNumber
1648
1657
  } else {
1649
- customMap[colKey] = { sortNumber }
1658
+ customMap[colKey] = { renderSortNumber }
1659
+ }
1660
+ if (!hasCustomSort) {
1661
+ hasCustomSort = true
1650
1662
  }
1651
1663
  })
1652
1664
  }
@@ -1673,6 +1685,7 @@ const Methods = {
1673
1685
  })
1674
1686
  }
1675
1687
  }
1688
+ let { collectColumn } = this
1676
1689
  const keyMap = {}
1677
1690
  XEUtils.eachTree(collectColumn, column => {
1678
1691
  const colKey = column.getKey()
@@ -1680,7 +1693,7 @@ const Methods = {
1680
1693
  keyMap[colKey] = column
1681
1694
  }
1682
1695
  })
1683
- XEUtils.each(customMap, ({ visible, resizeWidth, fixed, sortNumber }, field) => {
1696
+ XEUtils.each(customMap, ({ visible, resizeWidth, fixed, renderSortNumber }, field) => {
1684
1697
  const column = keyMap[field]
1685
1698
  if (column) {
1686
1699
  if (XEUtils.isNumber(resizeWidth)) {
@@ -1692,11 +1705,17 @@ const Methods = {
1692
1705
  if (fixed) {
1693
1706
  column.fixed = fixed
1694
1707
  }
1695
- if (sortNumber) {
1696
- column.colSeq = Number(sortNumber)
1708
+ if (renderSortNumber) {
1709
+ column.renderSortNumber = Number(renderSortNumber)
1697
1710
  }
1698
1711
  }
1699
1712
  })
1713
+ // 如果自定义了顺序
1714
+ if (hasCustomSort) {
1715
+ collectColumn = XEUtils.orderBy(collectColumn, 'renderSortNumber')
1716
+ this.collectColumn = collectColumn
1717
+ this.tableFullColumn = getColumnList(collectColumn)
1718
+ }
1700
1719
  }
1701
1720
  },
1702
1721
  saveCustomFixed () {
@@ -1785,6 +1804,35 @@ const Methods = {
1785
1804
  localStorage.setItem(resizableStorageKey, XEUtils.toJSONString(columnWidthStorageMap))
1786
1805
  }
1787
1806
  },
1807
+ saveCustomSort (isReset) {
1808
+ const { id, collectColumn, customConfig, customOpts } = this
1809
+ const { storage } = customOpts
1810
+ const isAllStorage = storage === true
1811
+ const storageOpts = isAllStorage ? {} : Object.assign({}, storage || {})
1812
+ const isSort = isAllStorage || storageOpts.sort
1813
+ if (customConfig && isSort) {
1814
+ const columnSortStorageMap = getCustomStorageMap(sortStorageKey)
1815
+ let columnWidthStorage
1816
+ if (!id) {
1817
+ errLog('vxe.error.reqProp', ['id'])
1818
+ return
1819
+ }
1820
+ if (!isReset) {
1821
+ columnWidthStorage = XEUtils.isPlainObject(columnSortStorageMap[id]) ? columnSortStorageMap[id] : {}
1822
+ // 排序只支持一级
1823
+ collectColumn.forEach(column => {
1824
+ if (column.sortNumber !== column.renderSortNumber) {
1825
+ const colKey = column.getKey()
1826
+ if (colKey) {
1827
+ columnWidthStorage[colKey] = column.renderSortNumber
1828
+ }
1829
+ }
1830
+ })
1831
+ }
1832
+ columnSortStorageMap[id] = XEUtils.isEmpty(columnWidthStorage) ? undefined : columnWidthStorage
1833
+ localStorage.setItem(sortStorageKey, XEUtils.toJSONString(columnSortStorageMap))
1834
+ }
1835
+ },
1788
1836
  handleUpdateDataQueue () {
1789
1837
  this.upDataFlag++
1790
1838
  },