Hi Team,
In grid component, I am using custom template for a column where I have ejs-autocomplete component in it. On change of value in autocomplete input, we need to change values of columns depending on it and also I need to update whole row's data.
so I want to update few/all columns of the row in grid based on value change in custom-template.
GRID
data properties
Custom_Template- In methods
I have screen recording gif, where on selection of "Item Code", all columns in the row are updated.
Thanks & Regards,
Sandeep G
|
// Edit auto complete’s change event handler
onChange(args) {
if (args.value === "Argentina") {
// Since the edit template creates a separate component instance, the Grid instance needs to be accessed from the root as shown below
var gridInst = this.$root.$children[0].$refs.grid.ej2Instances;
// The edit control id will be set as ‘Grid ID’ + ‘Column field name’ using which it can be accessed
// Here the ‘CustomerID’ column’s edit input is retrieved
var customerIDEle = gridInst.editModule.formObj.element.querySelector('#' + gridInst.element.id + 'CustomerID');
// The ‘CustomerID’ edit input value is modified
customerIDEle.value = 'VICTE';
}
} |
Hi Sujith,
when trying to get grid's instance using
var gridInst = this.$root.$children[0].$refs.grid.ej2Instances;
its throwing below errorError in console
package.json
component.vue
Regards,
Sandeep G
Hi Sujith,
I have tried with solution but issue still exits. I'm adding screenshots of consoles for reference
package.json - existing project
this.$rootthis.$root.$children
I have also tried replicating the same issue in sample project(I have commented few lines in datasource.js to avoid few errors). Its throwing different error. I am also adding project here.
Please let me know how to get grid's instance to update columns data
Thanks,
Sandeep G
Hi Sujith,
Thanks for your reply. It helped me to get grid's instance by identifying vue component from the "$root " and able to update fields. I also need to update hidden columns based on another edited column.
when trying to get form object using below method, I am unable to get hidden column elements
Unable to get and update hidden columns
Thanks,
Sandeep G
|
// Grid’s actionBegin event handler
actionBegin: function(args) {
// Check if event is triggered for save action
if (args.requestType === 'save') {
var newVal = args.data["Freight"] * 10;
// Here the new value can be updated to the hidden column field
args.data["Total"] = newVal;
}
} |
Hi Sujith,
Thanks for your reply, let me explain our requirement.
We need to have a autocomplete dropdown, where user will search and select item, and response of the autocomplete item contain data for the rest of the visible columns and hidden columns. So we can not update hidden columns on actionBegin (eventHandler) as it works only when user saves the grid.
I am supposed to update hidden columns when user changes value in one of the visible column. How can we achieve this?
Can we call actionBegin event inside a custom template and update hidden columns?
Regards,
Sandeep G
|
// Auto complete change event
onChange: function(args) {
...
// Here the response data is stored in a global variable
this.updatedData = resData;
}
},
// Grid’s actionBegin event handler
actionBegin: function(args) {
// Check if event is triggered for save action
if (args.requestType === 'save') {
// Here the updated response data stored is the global variable is retrieved
var newData = this.updatedData;
// The hidden column fields can now be updated with this data
args.data["PriceRet"] = newData["PriceRet"];
args.data["Discount"] = newData["Discount"];
}
}
|
Hi Sujith,
Thanks for your reply. When I try to update value of a column which has custom template, value is getting updated but after saving it we are not able to see updated value in grid. I am adding a sample where freight column has custom template.
How to update/save column's value which is having custom template in grid?