<template>
  <el-table ref="multipleTableRef" :data="tableData" style="width: 100%">
    <el-table-column type="selection" width="55" />
    <el-table-column label="时间" width="120">
      <template #default="scope">{{ scope.row.date }}</template>
    </el-table-column>
    <el-table-column property="name" label="姓名" width="120" />
    <el-table-column property="address" label="地址" show-overflow-tooltip />
  </el-table>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
import { ElTable } from 'element-plus'


const multipleTableRef = ref<any>()
const tableData = [
  {
    id: '1',
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: '2',
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: '3',
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: '4',
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },

]

//部分显示,默认回显 id 为 1 的勾选框
const toggleSelection = (rows: any) => {
  console.log( multipleTableRef.value,'值必须不为空');
  console.log(rows, 'table全部数据');
  const ids = ['1', '2', '4']
  if (rows) {
    rows.forEach((row: any) => {
      if(row.id === '1'){  //单个情况回显
      // if (ids.includes(row.id)) { // 判断当前行是否为默认回显行  数组多个数据回显情况
        multipleTableRef.value!.toggleRowSelection(row, true) // 默认勾选
      } else {
        multipleTableRef.value!.toggleRowSelection(row, false) // 不选中
      }
    })
  } else {
    multipleTableRef.value!.clearSelection()
  }
}
onMounted(() => {
  // getTableData()
  toggleSelection(tableData)
})
</script>

GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45 7 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐