React 版本 ag-grid https://www.ag-grid.com/react-data-grid/getting-started
Github https://github.com/ag-grid/ag-grid
构建企业级应用的表格,例如报告和数据分析,业务流程和数据输入的数据表格,
输出你想要的任何数据结果、数据结构、数据可视化;
支持 Excel 呈现数据的常规功能外,还包括分组计算、同步编辑、动态更新、迷你图、集成图表、独立图表等。

Community及 Enterprise两个版本,Enterprise版本收费

  • 大量数据处理和协作管理,需要付费
  • 付费版功能
    • 透视、分组、集成图表

网站 https://www.ag-grid.com
付费软件 https://www.ag-grid.com/license-pricing
image.png

  1. pnpm add ag-grid-react ag-grid-community ag-grid-enterprise

ag-Grid 每一个功能的文档至少有一个例子来展示该功能
https://blog.csdn.net/qq_43084458/article/details/122493617

image.png

AgGrid

  1. import { useState, useRef, useEffect, useMemo, useCallback } from "react";
  2. import { AgGridReact } from "ag-grid-react";
  3. import { Button } from 'antd'
  4. import 'ag-grid-enterprise';
  5. import 'ag-grid-community/styles/ag-grid.css'; // Core grid CSS, always needed
  6. import 'ag-grid-community/styles/ag-theme-alpine.css'; // Optional theme CSS
  7. const initRows = [
  8. { make: "Toyota", model: "Celica", price: 35000 },
  9. { make: "Ford", model: "Mondeo", price: 32000 },
  10. { make: "Porsche", model: "Boxter", price: 72000 }
  11. ]
  12. const AgGrid = () => {
  13. const gridRef = useRef();
  14. const [rowData, setRowData] = useState([]);
  15. const [columnDefs, setColumnDefs] = useState([
  16. { field: 'make', filter: true },
  17. { field: 'model', filter: true },
  18. { field: 'price', rowGroup: true }, // rowGroup 对行分组
  19. ]);
  20. useEffect(() => {
  21. setRowData(initRows)
  22. }, []);
  23. // DefaultColDef sets props common to all Columns
  24. const defaultColDef = useMemo(() => ({
  25. sortable: true
  26. }), []);
  27. // Example of consuming Grid Event
  28. const cellClickedListener = useCallback(event => {
  29. console.log('cellClicked', event);
  30. }, []);
  31. // Example using Grid's API
  32. const buttonListener = useCallback(e => {
  33. gridRef.current.api.deselectAll();
  34. }, []);
  35. return (
  36. <div
  37. className="ag-theme-alpine"
  38. style={{ height: 300, width: 602 }}
  39. >
  40. <Button type='primary' onClick={buttonListener}>获取数据</Button>
  41. <AgGridReact
  42. ref={gridRef}
  43. rowData={rowData}
  44. columnDefs={columnDefs}
  45. defaultColDef={defaultColDef} // Default Column Properties
  46. // Optional - set to 'true' to have rows animate when sorted
  47. animateRows={true}
  48. rowSelection='multiple' // allows click selection of rows
  49. onCellClicked={cellClickedListener} // registering for Grid Event
  50. />
  51. </div>
  52. );
  53. };
  54. export default AgGrid;