网站首页

人工智能P2P分享Wind搜索发布信息网站地图标签大全

当前位置:诺佳网 > 软件工程 > 前端开发 > Vue >

vxe-table 如何实现对单元格数据校验不通过的单元

时间:2026-01-04 10:14

人气:

作者:admin

标签:

导读:vxe-table 如何实现对单元格数据校验不通过的单元格显示背景颜色,通过设置 valid-config.theme=#39;beautify#39; 设置为高亮样式,调用 fullValidate 方法可以同时显示多个错误提示。 https://vxetable.c...

vxe-table 如何实现对单元格数据校验不通过的单元格显示背景颜色,通过设置 valid-config.theme='beautify' 设置为高亮样式,调用 fullValidate 方法可以同时显示多个错误提示。

https://vxetable.cn

通过设置 valid-config.showErrorBackground 显示校验错误单元格背景色

image

<template>
  <div>
    <div>
      <vxe-button @click="validEvent">多个校验变动数据</vxe-button>
      <vxe-button @click="fullValidEvent">多个校验全量数据</vxe-button>
    </div>
    <vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { VxeUI } from 'vxe-table'

const gridRef = ref()

const gridOptions = reactive({
  border: true,
  showOverflow: true,
  keepSource: true,
  height: 300,
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },
  validConfig: {
    msgMode: 'full',
    theme: 'beautify',
    showErrorBackground: true
  },
  editRules: {
    name: [
      { required: true, message: '必须填写' }
    ],
    role: [
      { required: true, message: '必须填写' }
    ]
  },
  columns: [
    { type: 'checkbox', width: 60 },
    { type: 'seq', width: 70 },
    { field: 'name', title: 'Name', editRender: { name: 'VxeInput' } },
    { field: 'role', title: 'Role', editRender: { name: 'VxeInput' } },
    { field: 'sex', title: 'Sex', editRender: { name: 'VxeInput' } },
    { field: 'age', title: 'Age', editRender: { name: 'VxeInput' } },
    { field: 'date', title: 'Date', editRender: { name: 'VxeInput' } }
  ],
  data: [
    { id: 10001, name: 'Test1', role: 'Develop', sex: '0', age: 28, address: 'test abc' },
    { id: 10002, name: '', role: 'Test', sex: '1', age: 22, address: 'Guangzhou' },
    { id: 10003, name: 'Test3', role: 'PM', sex: '', age: 32, address: 'Shanghai' },
    { id: 10004, name: 'Test4', role: 'Designer', sex: '', age: 23, address: 'test abc' },
    { id: 10005, name: '', role: '', sex: '1', age: 30, address: 'Shanghai' },
    { id: 10006, name: 'Test6', role: 'Designer', sex: '1', age: 21, address: 'test abc' }
  ]
})

const validEvent = async () => {
  const $grid = gridRef.value
  if ($grid) {
    const errMap = await $grid.fullValidate()
    if (errMap) {
      VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
    } else {
      VxeUI.modal.message({ status: 'success', content: '校验成功!' })
    }
  }
}

const fullValidEvent = async () => {
  const $grid = gridRef.value
  if ($grid) {
    const errMap = await $grid.fullValidate(true)
    if (errMap) {
      VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
    } else {
      VxeUI.modal.message({ status: 'success', content: '校验成功!' })
    }
  }
}
</script>

https://gitee.com/x-extends/vxe-table

温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信