UNPKG

@etsoo/materialui

Version:

TypeScript Material-UI Implementation

55 lines (54 loc) 2.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataTable = DataTable; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const ReactApp_1 = require("./app/ReactApp"); const DataGrid_1 = require("@mui/x-data-grid/DataGrid"); /** * Data table * @param props Props * @returns Component */ function DataTable(props) { // Global app const app = (0, ReactApp_1.useAppContext)(); // Destructor const { localeText = {}, onCellSelection, onProcessRowUpdateError = (error) => console.log("onProcessRowUpdateError", error), slotProps, ...rest } = props; // Labels const noRows = app?.get("noRows"); if (noRows && !localeText.noRowsLabel) localeText.noRowsLabel = noRows; const [cellModesModel, setCellModesModel] = react_1.default.useState({}); const handleCellFocus = react_1.default.useCallback((event) => { // event.target is the element that triggered the event // event.currentTarget is the element that the event listener is attached to const cell = event.currentTarget; const row = cell.parentElement; if (row == null) return; const id = row.dataset.id; const index = row.dataset.rowindex; const field = cell.dataset.field; if (id == null || index == null || field == null) return; const params = { id, field, index: parseInt(index) }; if (onCellSelection) { if (onCellSelection(params) === false) return; } }, []); return ((0, jsx_runtime_1.jsx)(DataGrid_1.DataGrid, { disableColumnMenu: true, hideFooter: true, localeText: localeText, cellModesModel: cellModesModel, onCellModesModelChange: (model) => setCellModesModel(model), onProcessRowUpdateError: onProcessRowUpdateError, slotProps: { ...slotProps, cell: { onFocus: handleCellFocus } }, ...rest })); }