[英]React Material UI Data Grid onSelectionModelChange with custome pagination
我在使用DataGrid
onSelectionModelChange
道具時遇到問題。 我可以獲得單個頁面的當前選定行,但是當我使用custom
分頁並移至下一頁並再次使用onSelectionModelChange
時,我丟失了之前的selections
。
function DataTable(props, list, count) {
const [page, setPage] = React.useState(1)
const [selectionModel, setSelectionModel] = React.useState([]);
const prevSelectionModel = React.useRef(selectionModel);
let history = useHistory();
const columns = [#cols here]
React.useEffect(() => {
listView(page, newSearch);
}, [page, newSearch]);
const data = {
columns: columns,
rows: JSON.parse(localStorage.getItem("results"))
}
return (
<div style={{ height: 600, width: '100%' }}>
<DataGrid
autoHeight
rows={data.rows}
columns={columns}
hideFooterPagination={true}
checkboxSelection
onSelectionModelChange={(ids) => {
setSelectionModel(ids);
console.log(selectionModel)
}}
pageSize={10}
rowsPerPageOptions={[10]}
// {...data}
/>
<AppPagination
setPage={setPage}
page={page}
/>
</div>
);
}
enter code here
道具keepNonExistentRowsSelected
適用於您的代碼。 更多信息參見Mui 數據網格文檔和github 問題
在 DataGrid 中使用 Props keepNonExistentRowsSelected。 如果 keepNonExistentRowsSelected 屬性為真,則選擇 model 將保留不存在的選定行。 在使用服務器端分頁時很有用,並且在更改頁面時需要保留行選擇。
<StyledDataGrid
keepNonExistentRowsSelected/>.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.