【发布时间】:2020-02-22 20:49:38
【问题描述】:
我正在尝试通过custom formatter 在Tabulator table 单元格中插入一个链接组件。
单元格中没有显示任何内容,如 the codesandbox 所示。
为什么不能从函数中返回 JSX? 我怎样才能做到这一点?
const invoiceLinkFormatter = (cell, formatterParams) => { // <------ Custom formatter definition
let key = cell.getValue();
let link = `/invoices/${key}`;
return (<Link to={link}>{key}</Link>);
};
invoicesTable.current = new Tabulator(refInvoicesTable.current, {
columns: [
{
title: "Invoices",
field: "invoiceKey",
formatter: invoiceLinkFormatter // <------ Custom formatter use
},
{ title: "Dates", field: "invoiceDate" }
]
});
这种方法有效,但由于链接离开反应应用程序并重新加载所有内容,它违背了目的。
const columns = [
{
title: "Invoice",
field: "invoiceKey",
formatter: "link",
formatterParams: { url: cell => { return "/invoices/" + cell.getValue() } }
},
{ title: "Date", field: "invoiceDate" },
];
【问题讨论】:
标签: javascript reactjs jsx tabulator