Add WIP on core formatting utils for row values
This commit is contained in:
parent
7a5b311a7e
commit
776f1cf61f
|
@ -8,7 +8,7 @@
|
|||
UISearchFilter,
|
||||
UserDatasource,
|
||||
} from "@budibase/types"
|
||||
import { fetchData, QueryUtils } from "@budibase/frontend-core/src"
|
||||
import { fetchData, QueryUtils, stringifyRow } from "@budibase/frontend-core"
|
||||
import { getContext } from "svelte"
|
||||
|
||||
type ProviderDatasource = Exclude<
|
||||
|
@ -39,6 +39,9 @@
|
|||
$: schema = sanitizeSchema($fetch.schema, columns)
|
||||
$: columnCount = Object.keys(schema).length
|
||||
$: rowCount = $fetch.rows?.length || 0
|
||||
$: stringifiedRows = ($fetch?.rows || []).map(row =>
|
||||
stringifyRow(row, schema)
|
||||
)
|
||||
|
||||
const createFetch = (datasource: ProviderDatasource) => {
|
||||
return fetchData({
|
||||
|
@ -95,7 +98,7 @@
|
|||
{#each Object.keys(schema) as col}
|
||||
<div class="cell header">{schema[col].displayName}</div>
|
||||
{/each}
|
||||
{#each $fetch.rows as row}
|
||||
{#each stringifiedRows as row}
|
||||
{#each Object.keys(schema) as col}
|
||||
<div class="cell">{row[col]}</div>
|
||||
{/each}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
<script context="module">
|
||||
const NumberFormatter = Intl.NumberFormat()
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { formatNumber } from "@budibase/frontend-core"
|
||||
import TextCell from "./TextCell.svelte"
|
||||
|
||||
export let api
|
||||
|
@ -13,18 +10,6 @@
|
|||
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
|
||||
|
|
|
@ -15,3 +15,4 @@ export * from "./relatedColumns"
|
|||
export * from "./table"
|
||||
export * from "./components"
|
||||
export * from "./validation"
|
||||
export * from "./formatting"
|
||||
|
|
Loading…
Reference in New Issue