您可以通过在columnDefs中使用valueGetter来获取单元格的值。下面是一个示例代码:
import React from "react";
import { AgGridReact } from "ag-grid-react";
import "ag-grid-community/dist/styles/ag-grid.css";
import "ag-grid-community/dist/styles/ag-theme-alpine.css";
const GridExample = () => {
const rowData = [
{ make: "Toyota", model: "Celica", price: 35000 },
{ make: "Ford", model: "Mondeo", price: 32000 },
{ make: "Porsche", model: "Boxter", price: 72000 },
];
const columnDefs = [
{ headerName: "Make", field: "make" },
{ headerName: "Model", field: "model" },
{ headerName: "Price", field: "price", valueGetter: "data.price" },
];
return (
);
};
export default GridExample;
在上面的示例中,我们定义了rowData和columnDefs。在columnDefs中,我们指定了valueGetter为"data.price",这意味着该列的值将从data.price属性中获取。您可以根据需要更改valueGetter的值来获取不同的属性值。
请确保已经安装了ag-Grid和ag-Grid React库,并将其导入到您的项目中。然后,您可以使用上述示例代码来创建一个包含ag-Grid表格的React组件。