By looking at the Stackblitz you shared it seems like you're not integrating Syncfusion right, they don't allow you to have controlled inputs in their templates because of their internal rendering logic.
Instead you should setup an event listener using a reference to the grid to listen to changes (keyup
) on grid elements and retrieve the changes (input value). Since the input will be uncontrolled (you're only passing a defaultValue
and you don't control what its current value will be) you won't have to update its value since it will be updated already (last thing the user typed).
I adapted the following code from their docs on edition to give you an idea on how to set it up:
function App() {
const grid = React.useRef<any>() // Keep a reference to the grid, we'll use it in the created function.
const gridTemplate = (props: any) => { // Similar gridTemplate function but just sets a default value and doesn't attach a React event handler, that will be handled on grid creation.
return (<div>
<input id={props.OrderID} defaultValue={props.Freight} className='custemp' type='text'/>
</div>);
};
const created = (args: any) => { // This function will be run by Syncfusion on creation
grid.current.element.addEventListener('keyup', function (e: any) {
if (e.target.classList.contains('custemp')) { // Based on condition, you can find whether the target is an input element or not.
let row = parentsUntil(e.target, 'e-row');
let rowIndex = row.rowIndex; // Get the row index.
let uid = row.getAttribute('data-uid');
let grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
let rowData = grid.getRowObjectFromUID(uid).data; // Get the row data.
rowData.Freight = e.target.value; // Update the new value for the corresponding column.
grid.current.updateRow(rowIndex, rowData); // Update the modified value in the row data.
}
});
};
return <GridComponent dataSource={data} ref={g => gridRef.current = g} height={315} created={created}>
<ColumnsDirective>
<ColumnDirective field='OrderID' headerText='Order ID' width='120' textAlign="Right" isPrimaryKey={true}/>
<ColumnDirective field='OrderDate' headerText='Order Date' width='130' textAlign="Right" format='yMd'/>
<ColumnDirective field='ShipCountry' headerText='Ship Country' width='140'/>
<ColumnDirective field='Freight' headerText='Receipt Amount' width='140' template={gridTemplate}/>
</ColumnsDirective>
</GridComponent>;
}
The code was originally written in plain Javascript.