Grid for React
React version of this topic (compatible with React 19+). Keep the same configuration logic from JavaScript and pass it as component props.
What this topic covers: practical setup, the framework-specific API access pattern, and copy-adapt guidance for the examples in this page.
import React, { useMemo, useRef } from 'react';
import { Grid } from 'smart-webcomponents-react/grid';
import 'smart-webcomponents-react/source/styles/smart.default.css';
export default function App() {
const componentRef = useRef(null);
const componentProps = useMemo(() => ({
// Copy this topic's JavaScript configuration here.
}), []);
return <Grid ref={componentRef} {...componentProps}></Grid>;
}
Use componentRef.current for API methods in this topic.
Build your web apps using Smart UI
Smart.Grid - Export Selected Records
Export Selected Records in Grid Component
Smart.Grid's export functionality allows the export of all data in various formats (such as XLSX, PDF, and HTML), as well as the export of only particular records of the Grid. This help topic shows how to export only the data of selected rows in the Grid.
The following TypeScript code shows how to export selected Grid rows to XLSX. Its functionality is detailed below.
const grid = <Grid>document.getElementById('grid'),
selection = componentRef.current.getSelection(); // (1)
let rowIdsToExport: (string | number)[];
if (selection.rows) {
rowIdsToExport = selection.rows.map((rowInfo: any) => rowInfo.row.id); // (2)
}
else {
rowIdsToExport = [];
}
componentRef.current.dataExport!.rowIds = rowIdsToExport; //(3)
componentRef.current.exportData('xlsx'); //(4)
- We get the Grid's selected row's by calling the method getSelection. If any records are selected, the object returned by this method contains a rows field - an array of objects with information about selected rows.
- This selected rows array is then converted to an array of row ids via map.
- The array of row ids to export is passed to the Grid's dataExport.rowIds property. Its default value is null, meaning that all records will be exported.
- Finally, the Grid's exportData method is called. In this case, the selected rows are exported to XLSX, but the Grid can also be exported to CSV, HTML, JPEG, PNG, JSON, PDF, TSV, and XML.
Note: If at a later time you wish to export all Grid rows, the dataExport.rowIds has to be reset by setting it to null.
For AI tooling
Developer Quick Reference
Topic: grid-export-selected-records Component: Grid Framework: React
Main methods: getSelection(), exportData()
Common config keys: (none detected)
Implementation Notes
Compatibility: React 19+ API access pattern: const componentRef = useRef(null) + componentRef.current.method()
Lifecycle guidance: Use useMemo for large config objects and call imperative API through componentRef.current after first render.
Common pitfalls:
- Recreating columns/dataSource objects on every render can reset component state.
- Calling API methods before ref is available causes runtime errors.
- Mixing controlled and imperative updates without sync can lead to stale UI.
Validation checklist:
- Keep config objects memoized when possible.
- Guard API calls with ref existence checks.
- Verify CSS theme import is present once per app.