mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
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:
@@ -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>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user