FPSMS-frontend
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 

83 строки
2.1 KiB

  1. "use client";
  2. import React, { useMemo } from "react";
  3. import { useTranslation } from "react-i18next";
  4. import { BomScoreResult } from "@/app/api/bom";
  5. import { GridColDef, GridValueFormatterParams } from "@mui/x-data-grid";
  6. import StyledDataGrid from "../StyledDataGrid";
  7. import Paper from "@mui/material/Paper";
  8. interface Props {
  9. boms: BomScoreResult[];
  10. }
  11. const BomScoreTable: React.FC<Props> = ({ boms }) => {
  12. const { t } = useTranslation(["bomWeighting", "common"]);
  13. const columns = useMemo<GridColDef<BomScoreResult>[]>(
  14. () => [
  15. {
  16. field: "code",
  17. headerName: t("Item Code"),
  18. flex: 1,
  19. minWidth: 150,
  20. },
  21. {
  22. field: "name",
  23. headerName: t("Item Name"),
  24. flex: 1.5,
  25. minWidth: 220,
  26. },
  27. {
  28. field: "baseScore",
  29. headerName: t("Base Score"),
  30. flex: 1,
  31. minWidth: 140,
  32. sortable: false,
  33. valueFormatter: (params: GridValueFormatterParams) => {
  34. const v = params.value;
  35. if (v == null) return "";
  36. let num: number | null = null;
  37. if (typeof v === "number") {
  38. num = v;
  39. } else if (typeof v === "string") {
  40. num = parseFloat(v);
  41. } else if (typeof v === "object" && v !== null) {
  42. const obj = v as any;
  43. if (typeof obj.value === "number") {
  44. num = obj.value;
  45. } else if (typeof obj.toString === "function") {
  46. num = parseFloat(obj.toString());
  47. }
  48. }
  49. if (num == null || Number.isNaN(num)) return "";
  50. return num.toFixed(2);
  51. },
  52. },
  53. ],
  54. [t],
  55. );
  56. return (
  57. <Paper variant="outlined" sx={{ overflow: "hidden" }}>
  58. <StyledDataGrid
  59. rows={boms}
  60. columns={columns}
  61. getRowId={(row) => row.id}
  62. autoHeight
  63. disableRowSelectionOnClick
  64. hideFooterPagination={true}
  65. sx={{
  66. "& .MuiDataGrid-columnHeaderTitle": { fontSize: 15 },
  67. "& .MuiDataGrid-cell": { fontSize: 16 },
  68. }}
  69. />
  70. </Paper>
  71. );
  72. };
  73. export default BomScoreTable;