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 } } } }
Hello Rohit,
I have been looking into your follow-up question, however, the described behavior is not reproducible with the sample that I have previously provided.
As can be observed in the below attachment, when adding a new row, entering a value for the 8D Action textbox, and selecting a value for the Location of Action dropdown, the appropriate function is called (getComboValueFor / getTextboxValueFor) and the correct value is returned. The same is valid when editing a row as well.
Having this in mind, since the sample provided by me seems to work successfully and as expected, this might indicate that the issues are local to your own environment and configuration.
Please check out once again the previously provided sample and test it on your side. If the behavior is not reproducible, review how each function is configured and how they are combined to work together.
It is possible that the current version of your application may differ from the one that I have used, so any new functionality that you have implemented may cause this unexpected behavior. Nevertheless, as previously mentioned, any further adjustments should be handled entirely by the developer since this functionality is not provided by the igGrid or the editors out of the box.
Attached can be found my sample for your reference.
Sincerely, Riva Ivanova Software Developer
5355.CustomDuplicatesSampleProperFunctionCall.zip
Hello Riva,
The 8d action column is now a combo/textbox depending on value of a checkbox. If checkbox is checked it's a combo else textbox. So , when it's a textbox it still fetching the value of drop-down? Could you help me with it? When I m using selection changed of location of action for new row, it's fetching the id of combo box not the value of textbox. Can you help me fix it?
As discussed in this and this forum post, attached can be found a modified version of your sample that demonstrates a duplication check. It uses the approach demonstrated in my previous response here, where I have defined a custom getComboValueFor function. For demonstration purposes, it is only implemented for the Location of Action column, but the same approach can be used for the custom textbox/combo editor provider. For the igCombo you can use its selectionChanged event, and for the igTextEditor you can use its valueChanged event.
More information about the supported options, events, and methods can be found in the respective API sections of the controls:
https://www.igniteui.com/help/api/2024.2/ui.igtexteditor
https://www.igniteui.com/help/api/2024.2/ui.igcombo
Please keep in mind that the provided sample is entirely implemented on the application level and aims to demonstrate a possible approach in achieving your requirements.
Having this in mind, since the igGrid does not provide this functionality out of the box, any further adjustments could be considered beyond the scope of Infragistics Support and should be handled entirely by the developer.
0218.CustomDuplicatesSample.zip
Thank you for your patience while I was looking into this matter for you.
After an investigation, what I can say is that there is no straightforward way provided by our API that allows getting a reference to the “Add new row” element and getting information about the entered data. A possible approach I can suggest is getting this reference manually via jQuery functions. Then, you should target the TD element that holds the combo editor and find the input element that holds the combo value.
For example:
function getComboValueFor(columnKey) { // Get "Add new row" TR element. const addRow = $("#grid").find('thead').children('tr[data-role="newrow"]')[0]; // Get target column index. const columnIndex = $("#grid").igGrid("option", "columns").findIndex(x => x.key === columnKey); // Get TD element of target column combo. const comboCell = addRow.cells[columnIndex]; // Get combo input element that holds combo value. const comboInput = $(comboCell).find('input.ui-igcombo-hidden-field'); // Get combo value. const comboValue = $(comboInput).val(); return comboValue; }
This custom getComboValueFor function can be used in the selectionChanged event for both editors. To get the appropriate value, you should provide the target column key.
{ 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, selectionChanged: function (evt, ui) { const combo = ui.owner; const rowId = combo.element.closest("tr[data-id]").attr("data-id"); // If rowID is undefined/null -> Add new row operation. if (!rowID) { const locationValue = getComboValueFor('location_of_action_id'); console.log(locationValue) } else { // Edit operation. } }, }, },
Here can be found a simplified sample demonstrating my suggestion.
Please keep in mind that since the igGrid does not provide this functionality out of the box, the provided sample is entirely implemented on the application level and aims to demonstrate a possible approach in achieving your requirements. It has not been tested for all possible scenarios and may require further adjustments.
Let me know if you need any further information on the matter.
Thank you for posting in our community!
This is an initial update to let you know that I am looking into your question and am currently in the process of creating a small sample that demonstrates the required behavior. I will keep you posted on my progress, and I will get back to you soon with more information or questions for you.
Please feel free to continue sending updates to this forum thread at any time.