mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 16:28:51 -06:00
web: Optimize table data updates
This commit is contained in:
@@ -370,6 +370,7 @@ const DataTable = (props: DataTableProps) => {
|
|||||||
const tableRef = useRef<Tabulator | null>(null);
|
const tableRef = useRef<Tabulator | null>(null);
|
||||||
const [isTableBuilt, setTableBuilt] = useState<Boolean>(false);
|
const [isTableBuilt, setTableBuilt] = useState<Boolean>(false);
|
||||||
const [activeCell, setActiveCell] = useState<CellComponent | null>(null);
|
const [activeCell, setActiveCell] = useState<CellComponent | null>(null);
|
||||||
|
const [currentTableData, setCurrentTableData] = useState<any[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onCellEdited = (cell: CellComponent) => {
|
const onCellEdited = (cell: CellComponent) => {
|
||||||
@@ -412,25 +413,36 @@ const DataTable = (props: DataTableProps) => {
|
|||||||
data: data,
|
data: data,
|
||||||
columns: columns,
|
columns: columns,
|
||||||
height: height,
|
height: height,
|
||||||
|
index: "Name",
|
||||||
});
|
});
|
||||||
tableRef.current.on("tableBuilt", () => {
|
tableRef.current.on("tableBuilt", () => {
|
||||||
setTableBuilt(true);
|
setTableBuilt(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTableBuilt) {
|
if (isTableBuilt) {
|
||||||
const newHeight = height;
|
const newHeight = height;
|
||||||
const newColumns = columns;
|
const newColumns = columns;
|
||||||
const newData = data;
|
const newTableData = data;
|
||||||
const oldRows = tableRef.current.getRows();
|
const oldRows = tableRef.current.getRows();
|
||||||
const activeRowPosition = activeCell?.getRow().getPosition() as number;
|
const activeRowPosition = activeCell?.getRow().getPosition() as number;
|
||||||
const activeField = activeCell?.getField();
|
const activeField = activeCell?.getField();
|
||||||
|
|
||||||
if (activeCell) {
|
|
||||||
console.log(activeCell.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update data
|
// Update data
|
||||||
tableRef.current.replaceData(newData).then(() => {});
|
if (newTableData.length === currentTableData.length) {
|
||||||
|
const updatedRows = newTableData.filter((_, i) => {
|
||||||
|
return (
|
||||||
|
JSON.stringify(newTableData[i]) !==
|
||||||
|
JSON.stringify(currentTableData[i])
|
||||||
|
);
|
||||||
|
});
|
||||||
|
if (updatedRows.length > 0) {
|
||||||
|
tableRef.current.updateData(updatedRows).then(() => {});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tableRef.current.replaceData(newTableData).then(() => {});
|
||||||
|
}
|
||||||
|
setCurrentTableData(newTableData);
|
||||||
|
|
||||||
// Restore active cell selection
|
// Restore active cell selection
|
||||||
if (activeCell) {
|
if (activeCell) {
|
||||||
|
|||||||
Reference in New Issue
Block a user