Merge pull request #14821 from Budibase/number-locale-strings

Display numbers using locale format in tables
This commit is contained in:
Andrew Kingston 2024-10-18 11:33:48 +01:00 committed by GitHub
commit cd8dcf412c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View File

@ -1,3 +1,7 @@
<script context="module">
const NumberFormatter = Intl.NumberFormat()
</script>
<script>
import TextCell from "./TextCell.svelte"
@ -9,6 +13,24 @@
const newValue = isNaN(float) ? null : float
onChange(newValue)
}
const formatNumber = value => {
const type = typeof value
if (type !== "string" && type !== "number") {
return ""
}
if (type === "string" && !value.trim().length) {
return ""
}
const res = NumberFormatter.format(value)
return res === "NaN" ? value : res
}
</script>
<TextCell {...$$props} onChange={numberOnChange} bind:api type="number" />
<TextCell
{...$$props}
onChange={numberOnChange}
bind:api
type="number"
format={formatNumber}
/>

View File

@ -7,11 +7,13 @@
export let type = "text"
export let readonly = false
export let api
export let format = null
let input
let active = false
$: editable = focused && !readonly
$: displayValue = format?.(value) ?? value ?? ""
const handleChange = e => {
onChange(e.target.value)
@ -52,7 +54,7 @@
{:else}
<div class="text-cell" class:number={type === "number"}>
<div class="value">
{value ?? ""}
{displayValue}
</div>
</div>
{/if}