Material-UI XGrid - 如何防止Delete键删除单元格内容
Material-UI XGrid - How to prevent Delete keys to delete cell content
有谁知道如何防止删除键清空反应Material-UI网格上的单元格内容?
今天,当您点击一个单元格并点击 删除 时,它会删除其内容。我想阻止它发生。
DataGrid
会将单元格数据设置为 empty string if you hit Delete or Backspace while not in edit mode. If you don't like that behavior, you can disable it by attaching a keydown
handler in the parent element in capture phase 并调用 stopPropagation()
:
<div
onKeyDownCapture={(e) => {
if (e.key === "Backspace" || e.key === "Delete") {
e.stopPropagation();
}
}}
style={{ height: 400, width: "100%" }}
>
<DataGrid rows={rows} columns={columns} />
</div>
现场演示
有谁知道如何防止删除键清空反应Material-UI网格上的单元格内容?
今天,当您点击一个单元格并点击 删除 时,它会删除其内容。我想阻止它发生。
DataGrid
会将单元格数据设置为 empty string if you hit Delete or Backspace while not in edit mode. If you don't like that behavior, you can disable it by attaching a keydown
handler in the parent element in capture phase 并调用 stopPropagation()
:
<div
onKeyDownCapture={(e) => {
if (e.key === "Backspace" || e.key === "Delete") {
e.stopPropagation();
}
}}
style={{ height: 400, width: "100%" }}
>
<DataGrid rows={rows} columns={columns} />
</div>