检查物料表行是否仍处于编辑模式 [英] Check if a material-table row is still in edit mode
问题描述
我正在
I'm using the material-table in a material-ui Stepper and the user tends to click on "next" button even though the table is still in edit mode. This results in a loss of data.
当用户单击下一步"按钮时,我可以以某种方式访问表信息以检查表/行是否仍处于编辑模式吗?
Can I somehow access the table information to check if the table/row is still in edit mode when the user clicks the "next" button?
推荐答案
虽然没有直接公开的方法可以告诉您该表是否为可编辑模式(我认为应该如此),但是您仍然可以找到它,但您将不得不对其内部进行一些修改.首先,您需要获取表的引用(查找 tableRef 属性),然后将为您提供帮助的属性是表状态中的 lastEditingRow
.
While there's no directly exposed method that would tell you if the table is editable mode or not (and I think there should be), you can still find it out, but you will have to mess a bit with it's internals. First you will need to grab the ref of the table (find tableRef property) and then the property that will help you is lastEditingRow
in the state of the table.
因此,具有 tableRef
将是: tableRef.current.state.lastEditingRow
.对于处于编辑模式的表,会将 lastEditingRow
设置为描述正在编辑的行的对象,如果表未处于编辑模式,则将设置为 undefined
.
So, having tableRef
that would be: tableRef.current.state.lastEditingRow
. For a table in editing mode lastEditingRow
will be set to an object describing the row being edited and undefined
if table is not in editing mode.
带有示例的CodeSandbox: https://codesandbox.io/s/fancy-waterfall-lg2ri
CodeSandbox with example for you: https://codesandbox.io/s/fancy-waterfall-lg2ri
这篇关于检查物料表行是否仍处于编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!