geido commented on code in PR #35343:
URL: https://github.com/apache/superset/pull/35343#discussion_r2472629174
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/AgGridTable/index.tsx:
##########
@@ -234,6 +287,55 @@ const AgGridDataTable: FunctionComponent<AgGridTableProps>
= memo(
[serverPagination, gridInitialState, percentMetrics, onSortChange],
);
+ const handleGridStateChange = useCallback(
+ debounce(() => {
+ if (onColumnStateChange && gridRef.current?.api) {
+ try {
+ const { api } = gridRef.current;
+
+ const columnState = api.getColumnState ? api.getColumnState() : [];
+
+ const filterModel = api.getFilterModel ? api.getFilterModel() : {};
+
+ const sortModel = columnState
+ .filter(col => col.sort)
+ .map(col => ({
+ colId: col.colId,
+ sort: col.sort as 'asc' | 'desc',
+ sortIndex: col.sortIndex || 0,
+ }))
+ .sort((a, b) => (a.sortIndex || 0) - (b.sortIndex || 0));
+
+ const stateToSave = {
+ columnState,
+ sortModel,
+ filterModel,
+ timestamp: Date.now(),
+ };
+
+ const stateHash = JSON.stringify({
+ columnOrder: columnState.map(c => c.colId),
+ sorts: sortModel,
+ filters: filterModel,
+ });
+
+ if (stateHash !== lastCapturedStateRef.current) {
+ lastCapturedStateRef.current = stateHash;
+
+ onColumnStateChange(stateToSave);
+ }
+ } catch (error) {
+ console.warn('Error capturing AG Grid state:', error);
+ onColumnStateChange({
+ timestamp: Date.now(),
+ hasChanges: true,
Review Comment:
What resets this eventually?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]