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