Hi,
I used the grid incell editing exemple ( https://www.telerik.com/kendo-react-ui/components/grid/editing/editing-in-cell/ ) to do modification in a list. The only thing I add to the exemple was the onBlur in the rowRender, because the exitEdit was not called anywhere.
Now I have a problem, because I have a delete button at the end of my row and if I click on it when i'm in edit the onClick event of my button is not called only the onBlur is called and I can't figure out what i'm doing wrong.
here is my custom row/cell render that I modified (I put the modification in bold)
import * as React from "react";
export const CellRender = (props) => {
const dataItem = props.originalProps.dataItem;
const cellField = props.originalProps.field;
const inEditField = dataItem[props.editField || ""];
const additionalProps =
cellField && cellField === inEditField
? {
ref: (td) => {
const input = td && td.querySelector("input");
const activeElement = document.activeElement;
if (
!input ||
!activeElement ||
input === activeElement ||
!activeElement.contains(input)
) {
return;
}
if (input.type === "checkbox") {
input.focus();
} else {
input.select();
}
},
}
: {
onClick: () => {
props.enterEdit(dataItem, cellField);
},
};
const clonedProps = {
...props.td.props,
...additionalProps,
};
return React.cloneElement(props.td, clonedProps, props.td.props.children);
};
export const RowRender = (props) => {
const trProps = {
...props.tr.props,
...{
onBlur: (e) => {
props.exitEdit()
}
}
};
return React.cloneElement(
props.tr,
{
...trProps,
},
props.tr.props.children
);
};
and here is the code for the components
const removeCell = (props) => {
const { dataItem } = props;
return (
<td className="k-command-cell">
<Button onClick={() => delete(dataItem)}><span className="k-icon k-font-icon k-i-close-outline k-icon-xl redIcon"></span></Button>
</td>
);
}
const customCellRender = (td, props) => (
<CellRender
originalProps={props}
td={td}
enterEdit={(dataItem, field) => setState(enterEdit(list, dataItem, field))}
editField={EDIT_FIELD}
/>
);
const customRowRender = (tr, props) => (
<RowRender
originalProps={props}
tr={tr}
exitEdit={() => setState(exitEdit())}
editField={EDIT_FIELD}
/>
);
const enterEdit = (list, dataItem, field) => {
return list.map((item) => ({
...item,
[EDIT_FIELD]: item.id=== dataItem.id? field : null,
}));
};
const exitEdit = () => {
return list.map((item) => ({
...item,
[EDIT_FIELD]: null,
}));
};
And here is my grid
<Grid
data={list}
dataItemKey={"id"}
total={list.length}
cellRender={customCellRender}
rowRender={customRowRender}
onItemChange={itemChange}
editField={EDIT_FIELD}
>
<GridToolbar>
<Button onClick={AddNewItem}><span className="k-icon k-font-icon k-i-plus-circle k-icon-xl greenIcon"></span> Add</Button>
</GridToolbar>
<Column field="Name" title="Name" editable={true} />
<Column title="Delete" cells={{ data: removeCell, }} width="100px"></Column>
</Grid>
Thanks you for your help.