Files
vxe-table/examples/plugins/table/formats.ts

36 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { VXETable } from '../../../packages/all'
import XEUtils from 'xe-utils'
// 自定义全局的格式化处理函数
VXETable.formats.mixin({
// 格式化性别
formatSex ({ cellValue }) {
return cellValue ? (cellValue === '1' ? '男' : '女') : ''
},
// 格式化下拉选项
formatSelect ({ cellValue }, list: any[]) {
const item = list.find(item => item.value === cellValue)
return item ? item.label : ''
},
// 格式化日期,默认 yyyy-MM-dd HH:mm:ss
formatDate ({ cellValue }, format?: string) {
return XEUtils.toDateString(cellValue, format || 'yyyy-MM-dd HH:mm:ss')
},
// 四舍五入金额每隔3位逗号分隔默认2位数
formatAmount ({ cellValue }, digits = 2) {
return XEUtils.commafy(XEUtils.toNumber(cellValue), { digits })
},
// 格式化银行卡默认每4位空格隔开
formatBankcard ({ cellValue }) {
return XEUtils.commafy(XEUtils.toValueString(cellValue), { spaceNumber: 4, separator: ' ' })
},
// 四舍五入,默认两位数
formatFixedNumber ({ cellValue }, digits = 2) {
return XEUtils.toFixed(XEUtils.round(cellValue, digits), digits)
},
// 向下舍入,默认两位数
formatCutNumber ({ cellValue }, digits = 2) {
return XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
}
})