dataeditor.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { GridCellKind } from "@glideapps/glide-data-grid"
  2. export function getDEColumn(columns, col) {
  3. let c = columns[col];
  4. c.pos = col;
  5. return c;
  6. }
  7. export function getDERow(data, row) {
  8. return data[row];
  9. }
  10. export function locateCell(row, column) {
  11. if (Array.isArray(row)) {
  12. return row[column.pos];
  13. } else {
  14. return row[column.id];
  15. }
  16. }
  17. export function formatCell(value, column) {
  18. switch (column.type) {
  19. case "int":
  20. case "float":
  21. return {
  22. kind: GridCellKind.Number,
  23. data: value,
  24. displayData: value + "",
  25. readonly: false,
  26. allowOverlay: false
  27. }
  28. case "datetime":
  29. // value = moment format?
  30. case "str":
  31. return {
  32. kind: GridCellKind.Text,
  33. data: value,
  34. displayData: value,
  35. readonly: false,
  36. allowOverlay: true
  37. }
  38. case "bool":
  39. return {
  40. kind: GridCellKind.Boolean,
  41. data: value,
  42. readonly: false,
  43. // allowOverlay: true
  44. }
  45. default:
  46. return {
  47. kind: GridCellKind.Text,
  48. data: value,
  49. displayData: "type not specified in column definition"
  50. }
  51. };
  52. };