当前位置:网站首页 > Vue.js开发 > 正文

vue3中,el-table表格的禁用、回显和多选操作——标识row-key、是否勾选selectable & toggleRowSelection(row, true)-true选中

vue3中,el-table表格的禁用、回显和多选操作——标识row-key、是否勾选selectable & toggleRowSelection(row, true)-true选中

效果

在这里插入图片描述

代码

index.vue

<!-- @Description 基金项目管理 - 基础设置 - 元数据维护 @author wdd @date 2023/10/31 --> <template> <div class="content"> <div class="set-box"> <el-table row-key="id" :header-cell-style="{ background: '#eef1f6' }" ref="tableRef" :data="metaTableData" class="table" @selection-change="handleSelectionChange"> <el-table-column type="selection" :selectable="isRow" width="50" align="center"></el-table-column> <el-table-column prop="fieldName" align="center" label="元数据名称"></el-table-column> <el-table-column prop="field" width="220" align="center" label="英文字段"></el-table-column> </el-table> <div> <el-button type="primary" size="default" @click="sureSubmit">提交</el-button> </div> </div> </div> </template> <script lang="ts" setup> import { ref,nextTick, inject} from 'vue'; import { ElMessage, ElMessageBox } from 'element-plus' import { post } from "@/utils/path.js"; const constant = inject('constant') const tableRef = ref() const metaTableData = ref([]) // 列表数据 const selectionList = ref([]) const getList = () => { post(constant.fundShowData + '/finance/template/field/get', ).then((res) => { const { code, data } = res.data if (code == '200') { metaTableData.value = data metaTableData.value.forEach(row=>{ // fieldType 选中标识 0-未选中 1-选中 if (row.fieldType == 1) { selectionList.value.push(row) nextTick(()=>{ tableRef.value.toggleRowSelection(row, true) // true为选中 }) } row.fieldType = 0 }) } }) } getList() // 多选 const handleSelectionChange = (val) => { selectionList.value = val; } // 禁用选项 const okLists = ref(['','','','','','']) const isRow=(row:any,rowIndex:any)=>{ return !okLists.value.includes(row.id) } // 提交 const sureSubmit = () => { selectionList.value.forEach(el=>{ metaTableData.value.forEach(item=>{ if(item.id == el.id){ item.fieldType = 1 } }) }) post(constant.fundShowData +'/finance/template/field/update', metaTableData.value).then((res) => { const { code, data } = res.data if (code == '200') { ElMessage.success("提交成功") getList() } }) } </script> <style lang="scss" scoped> .content { margin-top: 20px; margin-right: 20px; width: 100%; .set-box { margin: 20px 0; width: 60%; padding-left: 16px; } .el-button { float: right; margin-bottom: 10px; } .el-table { margin: 20px 0; } } </style> 
接口

data.json

{ 
    "success": true, "code": "200", "message": "操作成功", "data": [ { 
    "id": "", "field": "number", "fieldName": "单据编号", "fieldType": 1, "sort": 1 }, { 
    "id": "", "field": "projectName", "fieldName": "项目名称", "fieldType": 1, "sort": 2 }, { 
    "id": "", "field": "incomeExpensIllustrate", "fieldName": "收支说明", "fieldType": 1, "sort": 3 }, { 
    "id": "", "field": "incomeExpensDirection", "fieldName": "收支方向", "fieldType": 1, "sort": 4 }, { 
    "id": "", "field": "amount", "fieldName": "金额", "fieldType": 1, "sort": 5 }, { 
    "id": "", "field": "date", "fieldName": "日期", "fieldType": 1, "sort": 6 }, { 
    "id": "", "field": "projectNo", "fieldName": "项目编号", "fieldType": 0, "sort": 7 }, { 
    "id": "", "field": "projectBatch", "fieldName": "批次", "fieldType": 1, "sort": 8 }, { 
    "id": "", "field": "abstracts", "fieldName": "其他信息", "fieldType": 1, "sort": 9 }, { 
    "id": "", "field": "secondMotion", "fieldName": "附议信息", "fieldType": 0, "sort": 10 }, { 
    "id": "", "field": "operator", "fieldName": "操作人", "fieldType": 0, "sort": 11 } ], "result": 0, "total": "0" } 
到此这篇vue3中,el-table表格的禁用、回显和多选操作——标识row-key、是否勾选selectable & toggleRowSelection(row, true)-true选中的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • vue3中,tabs标签页的使用、调用方法实现动态style2024-11-30 19:45:09
  • vue3中,项目甘特图实现项目进度条——封装组件之tabs标签页的使用、定义方法实现动态样式style、reduce方法、数组每个下标对应的当前下标前几位之和、new Date()转换日期格式2024-11-30 19:45:09
  • vue中,401页面——您没有权限访问当前页面,直接跳转登录页2024-11-30 19:45:09
  • vue中,404页面——当前页面不存在,直接跳转首页2024-11-30 19:45:09
  • vue中,el-table树形数据与懒加载【实例】(二)——封装拖拽上传el-upload & 本地下载模板-public下的file文件夹 & JSON.parse转对象 & 表单禁止输入特殊字符2024-11-30 19:45:09
  • vue3中,el-table表格中基础的查询、重置、新增、编辑回显、删除2024-11-30 19:45:09
  • vue3中,wangEditor富文本组件的使用——.disable()富文本禁用、toolbarKeys配置菜单、shallowRef()创建实例、.destroy()销毁富文本、内容为html格式2024-11-30 19:45:09
  • vue3,下载预览的四种方法之responseType-blob、fileName、a标签下载& axios之post请求写法& 引入js方法文件写法& try和catch、async和await用法2024-11-30 19:45:09
  • vue3中,渲染动态表单(三)——梳理动态表单的几种类型、树结构表格row-key、父子传值之props、emit和defineEmits & ElLoading组件用法和post请求动态地址2024-11-30 19:45:09
  • vue3中,渲染动态表单(二)——使用wangEditor组件 & vue3基础页面的写法之defineComponent、toRefs、reactive和return & main文件注册全局组件2024-11-30 19:45:09
  • 全屏图片