move editable attribute to table Component
This commit is contained in:
parent
729150a5a4
commit
1a65af7602
3 changed files with 20 additions and 8 deletions
|
|
@ -17,6 +17,7 @@ interface TableComponentProps extends AgGridReactProps {
|
|||
rowData: NonNullable<AgGridReactProps["rowData"]>;
|
||||
alertTitle?: string;
|
||||
alertDescription?: string;
|
||||
editable?: boolean | string[];
|
||||
}
|
||||
|
||||
const TableComponent = forwardRef<
|
||||
|
|
@ -48,20 +49,30 @@ const TableComponent = forwardRef<
|
|||
}
|
||||
|
||||
const colDef = props.columnDefs.map((col, index) => {
|
||||
let newCol = {
|
||||
...col,
|
||||
headerName: toTitleCase(col.headerName),
|
||||
};
|
||||
if (props.onSelectionChanged && index === 0) {
|
||||
return {
|
||||
...col,
|
||||
headerName: toTitleCase(col.headerName),
|
||||
newCol = {
|
||||
...newCol,
|
||||
checkboxSelection: true,
|
||||
headerCheckboxSelection: true,
|
||||
headerCheckboxSelectionFilteredOnly: true,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
...col,
|
||||
headerName: toTitleCase(col.headerName),
|
||||
}
|
||||
console.log(props.editable, col.headerName);
|
||||
if (
|
||||
(typeof props.editable === "boolean" && props.editable) ||
|
||||
(Array.isArray(props.editable) &&
|
||||
props.editable.includes(newCol.headerName ?? ""))
|
||||
) {
|
||||
newCol = {
|
||||
...newCol,
|
||||
editable: true,
|
||||
};
|
||||
}
|
||||
return newCol;
|
||||
});
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ const useMessagesTable = (setColumns, setRows, setMessages) => {
|
|||
try {
|
||||
const data = await getMessagesTable("union", undefined, ["index"]);
|
||||
const { columns, rows } = data;
|
||||
setColumns(columns.map((col) => ({ ...col, editable: true })));
|
||||
setColumns(columns);
|
||||
setRows(rows);
|
||||
setMessages(rows);
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ export default function MessagesPage() {
|
|||
<Card x-chunk="dashboard-04-chunk-2" className="h-full pt-4">
|
||||
<CardContent className="h-full">
|
||||
<TableComponent
|
||||
editable={["Sender", "Sender Name", "Message"]}
|
||||
overlayNoRowsTemplate="No data available"
|
||||
onSelectionChanged={(event: SelectionChangedEvent) => {
|
||||
setSelectedRows(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue