问题描述:在React中使用Ag Grid作为表格组件,使用单元格渲染器渲染图标,但是图标无法点击。
解决方法:
// IconRenderer.js
import React from 'react';
const IconRenderer = ({ value, onClick }) => {
return (
);
};
export default IconRenderer;
// GridComponent.js
import React from 'react';
import { AgGridReact } from 'ag-grid-react';
import IconRenderer from './IconRenderer';
const GridComponent = () => {
const columnDefs = [
{
headerName: 'Icon',
field: 'icon',
cellRendererFramework: IconRenderer,
width: 100,
},
// other column definitions
];
const rowData = [
{ icon: 'fa fa-edit' },
// other row data
];
return (
);
};
export default GridComponent;
// index.js
import React from 'react';
import ReactDOM from 'react-dom';
import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';
import GridComponent from './GridComponent';
ReactDOM.render( , document.getElementById('root'));
这样,你就可以在React中使用Ag Grid的单元格渲染器渲染图标,并且可以点击图标了。