Hi Sir/Mam,
I hope you're doing well.
I'm working with an editable grid that has two dropdowns: location_of_action_id and action_id. On change of either dropdown, I need to check if the selected combination already exists in the grid using a checkIfDuplicateExists(location, action, rowId) function. This works perfectly during row editing, as the rowId is available and I can reference the pendingVersionUpdate[rowId] object to get the other value.
location_of_action_id
action_id
checkIfDuplicateExists(location, action, rowId)
rowId
pendingVersionUpdate[rowId]
However, when a new row is added, it doesn’t yet have a rowId, so I can't reliably access the corresponding entry in pendingVersionUpdate. As a result, I'm unable to fetch the other dropdown’s value for the duplicate check logic.
pendingVersionUpdate
Is there a recommended way to handle this scenario, such as identifying the current row context or maintaining values for new rows before a rowId is assigned?
Any suggestions or best practices would be greatly appreciated.
Best regards,Rohit Rawat
CODE REFERENCE
{ columnKey: "location_of_action_id", editorType: "combo", required: true, editorOptions: { dataSource: [{ code: "", name: "Select Location Of Action" }].concat(data_ddl.location_of_action), textKey: "name", valueKey: "code", mode: "dropdown", visibleItemsCount: 5, //value: function (rowIndex, columnKey) { // return this.grid.dataSource[rowIndex][columnKey]; //}, selectionChanged: function (evt, ui) { const combo = ui.owner; const selectedItem = ui.items[0]; debugger; const newValue = selectedItem ? selectedItem.data.code : "";
const rowId = combo.element.closest("tr[data-id]").attr("data-id"); if (!rowId) return;
if (!pendingVersionUpdate[rowId]) { const rowData = $("#master_grid").igGrid("findRecordByKey", rowId) || {}; pendingVersionUpdate[rowId] = { ...rowData }; }
pendingVersionUpdate[rowId].location_of_action_id = newValue;
const action = pendingVersionUpdate[rowId].action_id || ""; const location = newValue;
if (checkIfDuplicateExists(location, action, rowId)) { fnShowCommonPopup('error', "This combination already exists.", "Duplicate Entry"); combo.value(""); // Reset the combo } } } }, { columnKey: "action_id", editorType: "combo", required: true, editorOptions: { dataSource: [{ code: "", name: "Select 8D Action" }].concat(data_ddl.actions), textKey: "name", valueKey: "code", mode: "dropdown", visibleItemsCount: 5, //value: function (rowIndex, columnKey) { // return this.grid.dataSource[rowIndex][columnKey]; //}, selectionChanged: function (evt, ui) {
const combo = ui.owner; const selectedItem = ui.items[0]; const newValue = selectedItem ? selectedItem.data.code : "";
pendingVersionUpdate[rowId].action_id = newValue;
const location = pendingVersionUpdate[rowId].location_of_action_id || ""; const action = newValue;
if (checkIfDuplicateExists(location, action, rowId)) { fnShowCommonPopup('error', "This combination already exists.", "Duplicate Entry"); combo.value(""); // Reset the combo } } } }
Please help me out with this.