adds custom renderer for bool fields
This commit is contained in:
parent
67e176a69d
commit
e8e3a4c793
|
@ -1,4 +1,10 @@
|
||||||
<script>
|
<script>
|
||||||
|
// Import valueSetters
|
||||||
|
import { number } from "./valueSetters"
|
||||||
|
import { booleanRenderer } from "./customRenderer"
|
||||||
|
|
||||||
|
const setters = new Map([["number", number]])
|
||||||
|
|
||||||
import fetchData from "../fetchData.js"
|
import fetchData from "../fetchData.js"
|
||||||
import { isEmpty } from "lodash/fp"
|
import { isEmpty } from "lodash/fp"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
@ -17,17 +23,21 @@
|
||||||
console.log(datasource)
|
console.log(datasource)
|
||||||
const jsonModel = await _bb.api.get(`/api/models/${datasource.modelId}`)
|
const jsonModel = await _bb.api.get(`/api/models/${datasource.modelId}`)
|
||||||
const { schema } = await jsonModel.json()
|
const { schema } = await jsonModel.json()
|
||||||
|
console.log(schema)
|
||||||
if (!isEmpty(datasource)) {
|
if (!isEmpty(datasource)) {
|
||||||
data = await fetchData(datasource)
|
data = await fetchData(datasource)
|
||||||
if (data) {
|
if (data) {
|
||||||
// Construct column definitions
|
// Construct column definitions
|
||||||
columnDefs = Object.keys(schema).map(key => {
|
columnDefs = Object.keys(schema).map(key => {
|
||||||
return {
|
return {
|
||||||
|
valueSetter: setters.get(schema[key].type),
|
||||||
headerName: key.charAt(0).toUpperCase() + key.slice(1), // Capitalise first letter
|
headerName: key.charAt(0).toUpperCase() + key.slice(1), // Capitalise first letter
|
||||||
field: key,
|
field: key,
|
||||||
hide: shouldHideField(key),
|
hide: shouldHideField(key),
|
||||||
sortable: true,
|
sortable: true,
|
||||||
editable: true,
|
editable: schema[key].type !== "boolean",
|
||||||
|
cellRenderer:
|
||||||
|
schema[key].type === "boolean" ? booleanRenderer : null,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
export const booleanRenderer = (params) => {
|
||||||
|
const toggle = (e) => {
|
||||||
|
params.value = !params.value
|
||||||
|
params.setValue(e.currentTarget.checked)
|
||||||
|
}
|
||||||
|
let input = document.createElement("input")
|
||||||
|
input.type = "checkbox"
|
||||||
|
input.checked = params.value
|
||||||
|
input.addEventListener("click", toggle)
|
||||||
|
|
||||||
|
return input
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
// https://www.ag-grid.com/javascript-grid-value-setters/
|
||||||
|
// These handles values and makes sure they adhere to the data type provided by the model
|
||||||
|
export const number = (params) => {
|
||||||
|
console.log('Params: ', params)
|
||||||
|
console.log('New Value: ', parseFloat(params.newValue))
|
||||||
|
params.data[params.colDef.field] = parseFloat(params.newValue);
|
||||||
|
return true;
|
||||||
|
}
|
Loading…
Reference in New Issue