When the user clicks the grid add button I open a tile view that lets them select categories and products. Once they have selected the product, selected a unit of measure and entered a quantity. I build a row and add it to the grid. I need to be able to dynamically set the decimals property of the numericedit for the newly added row during creation.
The reason for this is products have different units of measure e.g. if the unit of measure is KG I want to set the decimals property of the numericedit decimals property to 3. If the Unit of Measure is EACH I want to set the numericedit decimals property to 0.
I have attached the grid snippet.
Hi Eli Abitbol,
Greetings from Syncfusion Support.
Based on your query, we understand that you would like to dynamically change the decimals property of the NumericTextBox editor based on the value selected in another column of the Grid.
You can achieve this using the actionComplete event of the Grid, which triggers after actions such as editing, sorting, filtering, paging, or grouping are completed:
You can customize the editor component within the actionComplete event when the requestType is either 'beginEdit' or 'add', as these conditions indicate that the Grid's edit form has been rendered.
https://ej2.syncfusion.com/javascript/documentation/api/grid/#actioncomplete
Additionally, you can use the change event of the NumericTextBox to dynamically update the decimals property when the related column value changes:
https://ej2.syncfusion.com/javascript/documentation/api/numerictextbox/#change
Please refer to the following code snippet and sample for more details.
|
actionComplete: (args) => { if (args.requestType === 'beginEdit' || args.requestType === 'add') { let unit = args.rowData.unit; let qnt = args.form.querySelector(".e-numerictextbox")['ej2_instances'][0]; qnt.decimals = unit === 'kg' ? 3 : 0; } } |
|
{ field: 'unit', headerText: 'UoM', width: 120, type: 'string',edit: { params: { change: () => change() }} , visible: true },
var formElement = grid.element.querySelector('form')['ej2_instances'][0]; let unit = formElement.getInputElement('unit').value; let qnt = formElement.getInputElement('quantity').previousSibling.ej2_instances[0]; qnt.decimals = unit === 'kg' ? 3 : 0; } |
Updated Sample: https://stackblitz.com/edit/ve4pwbhh-okqcq4tg?file=index.js,index.html
Documentation Link: https://ej2.syncfusion.com/javascript/documentation/grid/editing/in-line-editing#automatically-update-a-specific-column-based-on-another-column-edited-value
Regards,
Mohanraj Rengasamy
Yes. That worked thanks
Mohanraj.
Hi Eli Abitbol,
You are most welcome! Please get back to us if you need further assistance.
Regards,
Mohanraj Rengasamy