feat(table): Export table data with "Search box" enabled (#36281)

Co-authored-by: RebeccaH2003 <114100529+RebeccaH2003@users.noreply.github.com>
This commit is contained in:
Haoqian Zhang
2025-12-08 23:42:10 -05:00
committed by GitHub
parent 3940354120
commit f4b919bf7d
10 changed files with 765 additions and 44 deletions

View File

@@ -25,6 +25,7 @@ import {
MouseEvent,
KeyboardEvent as ReactKeyboardEvent,
useEffect,
useRef,
} from 'react';
import {
@@ -1354,6 +1355,50 @@ export default function TableChart<D extends DataRecord = DataRecord>(
}
};
// collect client-side filtered rows for export & push snapshot to ownState (guarded)
const [clientViewRows, setClientViewRows] = useState<DataRecord[]>([]);
const exportColumns = useMemo(
() =>
visibleColumnsMeta.map(col => ({
key: col.key,
label: col.config?.customColumnName || col.originalLabel || col.key,
})),
[visibleColumnsMeta],
);
// Use a ref to store previous clientViewRows and exportColumns for robust change detection
const prevClientViewRef = useRef<{
rows: DataRecord[];
columns: typeof exportColumns;
} | null>(null);
useEffect(() => {
if (serverPagination) return; // only for client-side mode
const prev = prevClientViewRef.current;
const rowsChanged = !prev || !isEqual(prev.rows, clientViewRows);
const columnsChanged = !prev || !isEqual(prev.columns, exportColumns);
if (rowsChanged || columnsChanged) {
prevClientViewRef.current = {
rows: clientViewRows,
columns: exportColumns,
};
updateTableOwnState(setDataMask, {
...serverPaginationData,
clientView: {
rows: clientViewRows,
columns: exportColumns,
count: clientViewRows.length,
},
});
}
}, [
clientViewRows,
exportColumns,
serverPagination,
setDataMask,
serverPaginationData,
]);
return (
<Styles>
<DataTable<D>
@@ -1391,6 +1436,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
onSearchChange={debouncedSearch}
searchOptions={searchOptions}
onFilteredDataChange={handleFilteredDataChange}
onFilteredRowsChange={setClientViewRows}
/>
</Styles>
);