gpt4 book ai didi

datagrid - Material UI 数据网格粘性标题

转载 作者:行者123 更新时间:2023-12-04 15:04:25 37 4
gpt4 key购买 nike

是否可以使 Material UI Datagrid Header 具有粘性?似乎这可以通过 Material UI Tables 实现。我无法找到使用数据网格执行此操作的选项。

最佳答案

正如评论中提到的,这是默认行为。
然而,很少有错误可以阻止这种默认功能。就我而言,这是我错过的属性(property):autoHeight={true} ,应该是false或者只是删除它。
这是一个广泛的代码示例,下面是 SandBox 的链接:

import { DataGrid, GridToolbar } from "@mui/x-data-grid";
import React from "react";

export default function AdvanceTable() {

const [pageSize, setPageSize] = React.useState(5);
const [editRowsModel, setEditRowsModel] = React.useState({});

const handleEditRowsModelChange = React.useCallback((model) => {
// Set current edited cell
setEditRowsModel(model);
});

return (
<div>
<div style={{ width: "100%", height: "80vh" }}>
<DataGrid
components={{
Toolbar: GridToolbar
}}
rows={rows}
columns={columns}
disableSelectionOnClick
checkboxSelection
onEditRowsModelChange={handleEditRowsModelChange}
pagination
pageSize={pageSize}
onPageSizeChange={(newPageSize) => setPageSize(newPageSize)}
rowsPerPageOptions={[5, 10, 15]}
/>
</div>
<div style={{ marginBottom: 8 }}>
<code>Edited table values: {JSON.stringify(editRowsModel)}</code>
</div>
</div>
);

// mock data:
const columns = [
{ field: "id", headerName: "ID", width: 70 },
{
field: "firstName",
headerName: "First name",
editable: true,
width: 180
},
{ field: "lastName", headerName: "Last name", editable: true, width: 180 },
{
field: "age",
headerName: "Age",
type: "number",
editable: true,
width: 150
}
];

const rows = [
{ id: 1, lastName: "Snow", firstName: "Jon", age: 35 },
{ id: 2, lastName: "Lannister", firstName: "Cersei", age: 42 },
{ id: 3, lastName: "Lannister", firstName: "Jaime", age: 45 },
{ id: 4, lastName: "Stark", firstName: "Arya", age: 16 },
{ id: 5, lastName: "Targaryen", firstName: "Daenerys", age: null },
{ id: 6, lastName: "Melisandre", firstName: null, age: 150 },
{ id: 7, lastName: "Clifford", firstName: "Ferrara", age: 44 },
{ id: 8, lastName: "Frances", firstName: "Rossini", age: 36 },
{ id: 9, lastName: "Roxie", firstName: "Harvey", age: 65 },
{ id: 41, lastName: "Stark", firstName: "Arya", age: 16 },
{ id: 51, lastName: "Targaryen", firstName: "Daenerys", age: null },
{ id: 61, lastName: "Melisandre", firstName: null, age: 150 },
{ id: 71, lastName: "Clifford", firstName: "Ferrara", age: 44 },
{ id: 81, lastName: "Frances", firstName: "Rossini", age: 36 },
{ id: 91, lastName: "Roxie", firstName: "Harvey", age: 65 }
];
}
SandBox example

关于datagrid - Material UI 数据网格粘性标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66435092/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com