Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1375
Issue with Duplicate Check on Newly Added Rows in Grid.
posted

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.

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.

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 : "";

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].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
}
}
}
}

Parents
No Data
Reply Children