我在我的react应用程序中使用 mui-datatable ,我想向表中添加水平滚动条以显示溢出列,而不是使表超出Windows屏幕宽度。
这是我的代码
const TableSection = (props) => {
const columns = [
{ name: "invoice_id", label: "Invoice No" },
{ name: "mode", label: "Mode" },
{ name: "date", label: "Date" },
{ name: "quantity", label: "Quantity" },
{ name: "status", label: "Status" },
{ name: "shipping_address_owner", label: "Customer" },
{
name: "product",
label: "Products",
options: {
customBodyRender: (value, tableMeta, updateValue) => (
<div>{value.join(",")}</div>
),
},
},
{
name: "payment_made",
label: "Amount paid",
options: {
customBodyRender: function (value, tableMeta, updateValue) {
return new Intl.NumberFormat().format(value); // comma separator
},
},
},
];
return (
<div className={classes.root}>
<Grid container spacing={3}>
<Grid item xs={12}>
<Paper className={classes.paper}>
<MUIDataTable
title={"Recent Purchases Invoice"}
data={invoiceData}
columns={columns}
options={options}
/>
</Paper>
</Grid>
</Grid>
</div>
);
};
export default TableSection;
const options = {
filterType: "checkbox",
rowsPerPage: 5,
rowsPerPageOptions: [5, 10, 15, 20],
downloadOptions: { filename: "InvoiceData.csv", separator: "," },
elevation: 6,
};
编辑:添加了表选项值
答案 0 :(得分:0)
createMuiTheme({
overrides: {
MUIDataTable: {
responsiveStacked: {
maxHeight: 'none',
overflowX:'auto'
},
},
},
});
在选项对象中,您可以传递响应属性。它具有3个不同的值...垂直,标准和简单。堆叠来自以前的版本,将很快弃用。
答案 1 :(得分:0)
您可以在选项中使用responsive: 'scrollMaxHeight'
来显示水平滚动。
const options = {
filterType: 'dropdown',
responsive: 'scrollMaxHeight',
count: total,
page: page,
rowsPerPage: tableState.rowsPerPage,
rowsPerPageOptions: [10, 20, 50, 100],
};
,然后将选项传递给MUIDataTable,如下所示:
<MUIDataTable
title={"Service Request List"}
data={requests}
columns={columns}
options={options}
/>