admin管理员组文章数量:1291309
I use React Devextreame DataGrid to handle change on cell change.
I found many events but I can't to know the column change and the new value after change.
I use batch edeting mode,virtual scrolling mode, i tried onKeyDown, but in can get what i need
<DataGrid
scrolling={{ mode: "virtual" }}
id={'id'}
dataSource={dataDateGrid}
onKeyDown={handleKeyDown} // Add key down event handler
onColumnsChange={val => {
console.log('onColumnsChange', val)
}}
onEditingChange={val => {
console.log('onEditingChange', val)
}}
>
<Editing
mode="batch"
allowUpdating
/>
</DataGrid >
I tried function onChangesChange but i think it is not coorect
const handleChangesChange = (changes: any) => {
if (changes.length > 0) {
// Find the latest change by comparing with previous changes
const latestChange = changes.find(
(change: any) => !previousChangesRef.current.includes(change)
);
if (latestChange) {
const { type, data, key, oldData } = latestChange;
if (type === 'update') {
// Compare oldData and data to find the changed column
for (const column in data) {
console.log('column: ', column);
console.log('data: ', data);
}
}
// Update the previous changes
previousChangesRef.current = changes;
}
}
}
I use React Devextreame DataGrid to handle change on cell change.
I found many events but I can't to know the column change and the new value after change.
I use batch edeting mode,virtual scrolling mode, i tried onKeyDown, but in can get what i need
<DataGrid
scrolling={{ mode: "virtual" }}
id={'id'}
dataSource={dataDateGrid}
onKeyDown={handleKeyDown} // Add key down event handler
onColumnsChange={val => {
console.log('onColumnsChange', val)
}}
onEditingChange={val => {
console.log('onEditingChange', val)
}}
>
<Editing
mode="batch"
allowUpdating
/>
</DataGrid >
I tried function onChangesChange but i think it is not coorect
const handleChangesChange = (changes: any) => {
if (changes.length > 0) {
// Find the latest change by comparing with previous changes
const latestChange = changes.find(
(change: any) => !previousChangesRef.current.includes(change)
);
if (latestChange) {
const { type, data, key, oldData } = latestChange;
if (type === 'update') {
// Compare oldData and data to find the changed column
for (const column in data) {
console.log('column: ', column);
console.log('data: ', data);
}
}
// Update the previous changes
previousChangesRef.current = changes;
}
}
}
Share
Improve this question
edited Feb 14 at 13:57
hakre
198k55 gold badges447 silver badges854 bronze badges
asked Feb 13 at 15:04
alaa-sufialaa-sufi
11 bronze badge
1 Answer
Reset to default 0You can use the onSaving callback to add functionality just before the cell/row changes are saved. You can compare the changes and check if a particular column is updated.
const onSaving = useCallback((e: DataGridTypes.SavingEvent) => {
// e.changes is an array of pending row changes
console.log(e.changes);
// Access the changed column & value
console.log(e.changes[0].data)
}, []);
And you can pass it as prop to the DataGrid
component:
<DataGrid
id="gridContainer"
dataSource={dataSource}
showBorders={true}
selectedRowKeys={selectedItemKeys}
onSelectionChanged={onSelectionChanged}
onSaving={onSaving}
>
...
</DataGrid>
You can also use the onSaved callback, but in this callback you will get the entire row which is going to be updated. So you need to compare with the old values to determine the changed cell.
本文标签: reactjsCell edit handler like onCellChangeStack Overflow
版权声明:本文标题:reactjs - Cell edit handler like onCellChange - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741528172a2383594.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论