在AntD表格中,列不会显示前导或尾随空格的解决方法如下所示:
import React from "react";
import { Table } from "antd";
const data = [
{
key: "1",
name: " John ",
age: 32,
address: " New York ",
},
{
key: "2",
name: " Jane ",
age: 28,
address: " London ",
},
{
key: "3",
name: " Bob ",
age: 40,
address: " Sydney ",
},
];
const columns = [
{
title: "Name",
dataIndex: "name",
key: "name",
render: (text) => text.trim(), // 使用trim()方法去除前导和尾随空格
},
{
title: "Age",
dataIndex: "age",
key: "age",
},
{
title: "Address",
dataIndex: "address",
key: "address",
render: (text) => text.trim(), // 使用trim()方法去除前导和尾随空格
},
];
const App = () => {
return
;
};
export default App;
在上面的示例代码中,通过在render属性中使用trim()方法,将列值中的前导和尾随空格去除。这样,AntD表格中的列将不会显示前导或尾随空格。