如何用 vxe-table 实现单元格内容格式化金额,千位分隔符,负数显示红色

如何用 vxe-table 实现单元格内容格式化金额,千位分隔符,负数显示红色

查看官网:https://vxetable.cn
gitbub:https://github.com/x-extends/vxe-table
gitee:https://gitee.com/x-extends/vxe-table

在 vxe-table 配置格式化金额非常简单,通过内置的数值格式化器就可以直接配置实现。
cellRender: { name: ‘FormatNumberInput’, showNegativeStatus: true, props: { type: ‘amount’ } }

其中 showNegativeStatus 是当数组为负数时,是否自动显示红色,如果 type=amount 时,可以配置是否千位分隔和现实货币符号

<template>
  <div>
    <vxe-grid v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import type { VxeGridProps } from 'vxe-table'

interface RowVO {
  id: number
  name: string
  role: string
  sex: string
  age: number
  address: string
  num1: number | null
  num2: number | null
  num3: number | null
  num4: number | null
}

const gridOptions = reactive<VxeGridProps<RowVO>>({
  border: true,
  showOverflow: true,
  columns: [
    { type: 'seq', width: 70 },
    { field: 'name', title: 'Name' },
    { field: 'num1', title: '数值', cellRender: { name: 'FormatNumberInput' } },
    { field: 'num2', title: '数值(负数标红)', cellRender: { name: 'FormatNumberInput', showNegativeStatus: true } },
    { field: 'num3', title: '货币', align: 'right', cellRender: { name: 'FormatNumberInput', props: { type: 'amount', align: 'right', showCurrency: true } } },
    { field: 'num4', title: '货币(负数标红)', align: 'right', cellRender: { name: 'FormatNumberInput', showNegativeStatus: true, props: { type: 'amount', align: 'right', showCurrency: true } } }
  ],
  data: [
    { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc', num1: 10000000, num2: 10000000, num3: 10000000, num4: 10000000 },
    { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou', num1: -20000, num2: -20000, num3: -20000, num4: -20000 },
    { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai', num1: null, num2: null, num3: null, num4: null },
    { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai', num1: 0, num2: 0, num3: 0, num4: 0 }
  ]
})
</script>

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

来源链接:https://www.cnblogs.com/qaz666/p/18779466

© 版权声明
THE END
支持一下吧
点赞14 分享
评论 抢沙发
头像
请文明发言!
提交
头像

昵称

取消
昵称表情代码快捷回复

    暂无评论内容