关于elementui plus table的一些操作

发布于:2024-08-20 ⋅ 阅读:(122) ⋅ 点赞:(0)

表格选择回显

//单条回显
pickTable.value.toggleRowSelection(row, true)
//回显后 全选
const handleSelectionChange = (val: any) => {
  val.map((row: any, index: any) => {
    if (val.length <= 1) {
      return
    }
    pickTable.value.toggleRowSelection(row, false)
    if (index === val.length - 1) {
      pickTable.value.toggleRowSelection(row, true)
    }
  })
}

获取表格所有选项

const arr = pickTable.value.getSelectionRows()

清空选项

 tableRef.value.clearSelection()

树表格懒加载

<el-table v-loading="loading" ref="tableRef" lazy class="custom-table" :data="tableData" row-key="uuid"
          :load="load" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          :header-row-style="config.table.header.row" :header-cell-style="config.table.header.cell" :border="true"
          @select="handleSelect" @select-all="handleSelectAll">
          <el-table-column type="selection" reserve-selection width="55" :selectable="selectable" />
          <el-table-column label="工作事项" prop="name" />
        </el-table

//获取列表时需要
 tableData.value.forEach((e) => {
          e["hasChildren"] = true;
          e["leave"] = 1;
          rowMaps.set(e.uuid, e);
        });

//懒加载展开
const load = (row: AssessWorkMatter, treeNode: unknown, resolve: (data: AssessWorkMatter[]) => void) => {
  getSubBaseAuditMatterList(row.uuid).then((data: any) => {
    resolve(data);
  })
};
 
//刷新 stageUuid是父节点的id
const materialRefench = () => {
  if (!stageUuid.value) return
  const data = rowMaps.get(stageUuid.value)
  // 重置节点
  tableRef.value.store.states.treeData.value[data.uuid].loaded = false;
  // 数据处理完成后 加载数据并展开父节点
  tableRef.value.store.loadOrToggle(data);
};


网站公告

今日签到

点亮在社区的每一天
去签到