在react-bootstrap-table2中设置边框上的图标可以通过自定义样式来实现。以下是一种可能的方法:
import BootstrapTable from 'react-bootstrap-table-next';
import 'react-bootstrap-table-next/dist/react-bootstrap-table2.min.css';
import 'bootstrap/dist/css/bootstrap.min.css';
const customCellStyle = (cell, row, rowIndex, colIndex) => {
return {
border: '1px solid #ddd',
padding: '8px',
position: 'relative',
};
};
const iconStyle = {
position: 'absolute',
top: '50%',
right: '8px',
transform: 'translateY(-50%)',
color: '#999',
};
const columns = [
{
dataField: 'id',
text: 'ID',
style: customCellStyle,
headerStyle: customCellStyle,
},
{
dataField: 'name',
text: 'Name',
style: customCellStyle,
headerStyle: customCellStyle,
},
{
dataField: 'actions',
text: 'Actions',
style: customCellStyle,
headerStyle: customCellStyle,
formatter: (cell, row) => (
<div>
<span>{cell}</span>
<i className="fa fa-edit" style={iconStyle}></i>
</div>
),
},
];
const data = [
{ id: 1, name: 'John Doe', actions: 'Edit' },
{ id: 2, name: 'Jane Smith', actions: 'Edit' },
];
const MyTable = () => {
return <BootstrapTable keyField='id' data={data} columns={columns} />;
};
在上面的代码中,我们定义了一个包含ID、Name和Actions列的表格。在Actions列中,我们使用了一个自定义的formatter函数来渲染单元格内容,并在内容后面添加了一个编辑图标。
请注意,上述代码中使用的图标类名fa fa-edit
是Font Awesome图标库的类名。如果你使用的是其他图标库,你需要相应地修改类名。
这是一个简单的示例,你可以根据自己的需求进行修改和扩展。希望对你有帮助!
领取专属 10元无门槛券
手把手带您无忧上云