如何用 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
© 版权声明
本站所有资源来自于网络,仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您(转载者)自己承担!
如有侵犯您的版权,请及时联系3500663466#qq.com(#换@),我们将第一时间删除本站数据。
如有侵犯您的版权,请及时联系3500663466#qq.com(#换@),我们将第一时间删除本站数据。
THE END
暂无评论内容