How to use the xe-utils/methods/xe-utils.eachTree function in xe-utils

To help you get started, we’ve selected a few xe-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xuliangzhan / vxe-table / packages / export / src / mixin.js View on Github external
function getLabelData ($xetable, opts, columns, datas) {
  const { treeConfig, treeOpts, scrollXLoad, scrollYLoad } = $xetable
  if (treeConfig) {
    // 如果是树表格只允许导出数据源
    const rest = []
    XEUtils.eachTree(datas, (row, rowIndex, items, path, parent, nodes) => {
      let item = {
        _level: nodes.length - 1,
        _hasChild: hasTreeChildren($xetable, row)
      }
      columns.forEach((column, columnIndex) => {
        let cellValue = ''
        switch (column.type) {
          // v3.0 废弃 type=index
          case 'seq':
          case 'index':
            cellValue = getSeq($xetable, row, rowIndex, column, columnIndex)
            break
          // v3.0 废弃 type=selection
          case 'selection':
          case 'checkbox':
            cellValue = $xetable.isCheckedByCheckboxRow(row)
github xuliangzhan / vxe-table / packages / virtual-tree / src / virtual-tree.js View on Github external
handleExpanding (row) {
      if (this.hasChilds(row)) {
        const { tableData, treeConfig } = this
        let childRows = row[treeConfig.children]
        let expandList = []
        let rowIndex = tableData.indexOf(row)
        if (rowIndex === -1) {
          throw new Error('错误的操作!')
        }
        XEUtils.eachTree(childRows, (item, index, obj, paths, parent, nodes) => {
          if (!parent || parent._X_EXPAND) {
            expandList.push(item)
          }
        }, treeConfig)
        row._X_EXPAND = true
        tableData.splice.apply(tableData, [rowIndex + 1, 0].concat(expandList))
      }
      return this.tableData
    },
    // 收起节点
github xuliangzhan / vxe-table / packages / table / src / methods.js View on Github external
parentStatus = selectItems.filter(item => vItems.indexOf(item) > -1).length === vItems.length ? true : (selectItems.length || value === -1 ? -1 : false)
          }
          return this.handleSelectRow({ row: matchObj.parent }, parentStatus)
        }
      } else {
        XEUtils.set(row, property, value)
        this.handleSelectReserveRow(row, value)
      }
    } else {
      if (treeConfig && !checkStrictly) {
        if (value === -1) {
          treeIndeterminates.push(row)
          XEUtils.remove(selection, item => item === row)
        } else {
          // 更新子节点状态
          XEUtils.eachTree([row], (item, $rowIndex) => {
            if (row === item || (!checkMethod || checkMethod({ row: item, $rowIndex }))) {
              if (value) {
                selection.push(item)
              } else {
                XEUtils.remove(selection, select => select === item)
              }
              this.handleSelectReserveRow(row, value)
            }
          }, treeOpts)
          XEUtils.remove(treeIndeterminates, item => item === row)
        }
        // 如果存在父节点,更新父节点状态
        let matchObj = XEUtils.findTree(afterFullData, item => item === row, treeOpts)
        if (matchObj && matchObj.parent) {
          let parentStatus
          let vItems = checkMethod ? matchObj.items.filter((item, $rowIndex) => checkMethod({ row: item, $rowIndex })) : matchObj.items
github xuliangzhan / vxe-table / packages / table / src / methods.js View on Github external
cacheColumnMap () {
    let { isGroup, tableFullColumn, collectColumn, fullColumnMap } = this
    let fullColumnIdData = this.fullColumnIdData = {}
    fullColumnMap.clear()
    if (isGroup) {
      XEUtils.eachTree(collectColumn, (column, index) => {
        if (column.children && column.children.length) {
          let rest = { column, colid: column.id, index }
          fullColumnIdData[column.id] = rest
          fullColumnMap.set(column, rest)
        }
      }, headerProps)
    }
    tableFullColumn.forEach((column, index) => {
      let rest = { column, colid: column.id, index }
      fullColumnIdData[column.id] = rest
      fullColumnMap.set(column, rest)
    }, headerProps)
  },
  /**
github xuliangzhan / vxe-table / packages / validator / src / mixin.js View on Github external
if (!validRest[column.property]) {
                          validRest[column.property] = []
                        }
                        validRest[column.property].push(rest)
                        return resolve()
                      }
                      return reject(rest)
                    })
                })
              )
            }
          })
          rowValids.push(Promise.all(colVailds))
        }
        if (treeConfig) {
          XEUtils.eachTree(vaildDatas, handleVaild, treeOpts)
        } else {
          vaildDatas.forEach(handleVaild)
        }
        return Promise.all(rowValids).then(() => {
          let ruleProps = Object.keys(validRest)
          if (ruleProps.length) {
            return Promise.reject(validRest[ruleProps[0]][0])
          }
          if (cb) {
            cb(status)
          }
        }).catch(params => {
          const args = isAll ? validRest : { [params.column.property]: params }
          return new Promise((resolve, reject) => {
            const finish = () => {
              status = false
github xuliangzhan / vxe-table / packages / virtual-tree / src / virtual-tree.js View on Github external
getTreeExpandRecords () {
      const hasChilds = this.hasChilds
      const treeExpandRecords = []
      XEUtils.eachTree(this.fullTreeData, row => {
        if (row._X_EXPAND && hasChilds(row)) {
          treeExpandRecords.push(row)
        }
      }, this.treeConfig)
      return treeExpandRecords
    },
    clearTreeExpand () {
github xuliangzhan / vxe-table / packages / table / src / methods.js View on Github external
appendTreeCache (row, childs) {
    let { keepSource, tableSourceData, treeOpts, fullDataRowIdData, fullDataRowMap, fullAllDataRowMap, fullAllDataRowIdData } = this
    let { children, hasChild } = treeOpts
    let rowkey = UtilTools.getRowkey(this)
    let rowid = UtilTools.getRowid(this, row)
    let matchObj
    if (keepSource) {
      matchObj = XEUtils.findTree(tableSourceData, item => rowid === UtilTools.getRowid(this, item), treeOpts)
    }
    XEUtils.eachTree(childs, (row, index) => {
      let rowid = UtilTools.getRowid(this, row)
      if (!rowid) {
        rowid = getRowUniqueId()
        XEUtils.set(row, rowkey, rowid)
      }
      if (row[hasChild] && XEUtils.isUndefined(row[children])) {
        row[children] = null
      }
      let rest = { row, rowid, index }
      fullDataRowIdData[rowid] = rest
      fullDataRowMap.set(row, rest)
      fullAllDataRowIdData[rowid] = rest
      fullAllDataRowMap.set(row, rest)
    }, treeOpts)
    if (matchObj) {
      matchObj.item[children] = XEUtils.clone(childs, true)
github xuliangzhan / vxe-table / packages / table / src / methods.js View on Github external
XEUtils.arrayEach(listElem.querySelectorAll(`.col--group`), thElem => {
              let column = this.getColumnNode(thElem).item
              let { showHeaderOverflow } = column
              let cellOverflow = XEUtils.isBoolean(showHeaderOverflow) ? showHeaderOverflow : allColumnHeaderOverflow
              let showEllipsis = cellOverflow === 'ellipsis'
              let showTitle = cellOverflow === 'title'
              let showTooltip = cellOverflow === true || cellOverflow === 'tooltip'
              let hasEllipsis = showTitle || showTooltip || showEllipsis
              let childWidth = 0
              let countChild = 0
              if (hasEllipsis) {
                XEUtils.eachTree(column.children, item => {
                  if (!item.children || !column.children.length) {
                    countChild++
                  }
                  childWidth += item.renderWidth
                })
                thElem.style.width = `${childWidth - countChild - (border ? 2 : 0)}px`
              }
            })
          }
github xuliangzhan / vxe-table / packages / table / src / methods.js View on Github external
}
        }
        let clearValFn = (row, rowIndex) => {
          if (!checkMethod || (checkMethod({ row, [indexKey]: rowIndex, $rowIndex: rowIndex }) ? 0 : selection.indexOf(row) > -1)) {
            XEUtils.set(row, property, value)
          }
        }
        if (treeConfig) {
          XEUtils.eachTree(afterFullData, value ? setValFn : clearValFn, treeOpts)
        } else {
          afterFullData.forEach(value ? setValFn : clearValFn)
        }
      } else {
        if (treeConfig) {
          if (value) {
            XEUtils.eachTree(afterFullData, (row, $rowIndex) => {
              if (!checkMethod || checkMethod({ row, $rowIndex })) {
                selectRows.push(row)
              }
            }, treeOpts)
          } else {
            if (checkMethod) {
              XEUtils.eachTree(afterFullData, (row, $rowIndex) => {
                if (checkMethod({ row, $rowIndex }) ? 0 : selection.indexOf(row) > -1) {
                  selectRows.push(row)
                }
              }, treeOpts)
            }
          }
        } else {
          if (value) {
            if (checkMethod) {