Hello sir/mam,
I have two columns. One is checkbox and the datatype of other column will depend on the value of the checkbox. If it is checked the datatype of second column will be combo/dropdown. If it is unchecked then then the datatype of second column will be text. I need help how to implement this functionality. Could you please help me out.Thanks and Regards
Rohit Rawat
Hello Rohit,
I have been looking into your question and noticed that the same one is asked in this forum thread here and also in this forum thread here. Please note that, according to our support policy, we handle a single question per case, and the current theme is regarding dynamically changing a column editor. Also, we handle a single forum thread/support case per question.
It is not recommended to post the same question in multiple forum posts or to post questions that are not related to the original theme. This is for better consistency and history tracking.
Having this in mind, the current question will be addressed in the following forum post here.
If you need any further information regarding dynamically changing the column editor, please let me know.
Sincerely, Riva Ivanova Software Developer
When i m adding new row. Its showing validation error in the starting why?Could you help me with it
return [ { columnKey: "action_id", readOnly: false, required: true, editorProvider: new $.ig.EditorProviderComboTextbox() }, { columnKey: "Delivered", editorType: "checkbox", editorOptions: { valueChanging: function (evt, ui) { const checkbox = ui.newValue const combo = $("#combo") const txtEditor = $("#textEditor") // Reset both editors to default const resetEditors = () => { combo.igCombo("value", "0"); txtEditor.igTextEditor("value", ""); }; resetEditors(); if (checkbox) { txtEditor.hide() combo.show() editorProvider.currentEditor = combo } else { txtEditor.show() combo.hide() editorProvider.currentEditor = txtEditor } // createControls(checkbox); } } }, { columnKey: "version_no", readOnly: true // Make this column read-only }, { 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, allowTooltips: true, 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].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 } } } },the location of action column is giving error on add row . On edit its working fine.
editRowStarted: function (evt, ui) { $("#master_grid_updating_cancel").off("click").on("click", function () { $("#master_grid").igGrid("hideColumn", "Delivered"); });
$("#master_grid_updating_done").off("click").on("click", function () { $("#master_grid").igGrid("hideColumn", "Delivered"); }); }, editRowEnding: function (evt, ui) { if (editStarting) { $("#master_grid").igGridUpdating("endEdit") editStarting = false return false } }, editRowStarting: function (evt, ui) { if (!window.allowEditFromIcon && ui.rowAdding == false) { evt.preventDefault(); } rowID = ui.rowID editStarting = true $("#master_grid").igGrid("showColumn", "Delivered", function () { $("#master_grid").igGridUpdating("endEdit") if (ui.rowID) { $("#master_grid").igGridUpdating("startEdit", ui.rowID, 0) } else { $("#master_grid").igGridUpdating("startAddRowEdit") } }) }, editCellStarting: function (evt, ui) { // Block edit unless it's triggered via the icon if (!window.allowEditFromIcon && ui.rowAdding == false) { evt.preventDefault(); } }, // Handling when the cell edit is ending editCellEnding: function (evt, ui) { // toggleStandardCheckbox(); // toggleStandardCheckbox(true); let rowId = ui.rowID;
// If it's a new row (rowId is null), generate a temporary unique rowId if (!rowId) { rowId = `new_row_${Date.now()}`; // Create a unique temporary rowId using timestamp }
// If no entry exists for this rowId, copy the current row data or create a new entry if (!pendingVersionUpdate[rowId]) { const rowData = $("#master_grid").igGrid("findRecordByKey", rowId) || {}; // Fallback to empty object if new row pendingVersionUpdate[rowId] = { ...rowData }; // Create a shallow copy of row data }
// Save the in-progress edit for this row pendingVersionUpdate[rowId][ui.columnKey] = ui.value ?? ""; },
// Handling when the cell edit is completed editCellEnded: function (evt, ui) { let rowId = ui.rowID; // If it's a new row (rowId is null), use the generated temporary rowId if (!rowId) { rowId = `new_row_${Date.now()}`; }
// If no entry exists for this rowId, return (exit) if (!pendingVersionUpdate[rowId]) return;
const updatedRow = pendingVersionUpdate[rowId]; const location = updatedRow.location_of_action_id || ""; const action = updatedRow.action_id || ""; // Get the location and action values from the edited row
if (location && action) { const version = generateVersion(location, action);
// Safely update version_no after the grid commits the cell $("#master_grid").igGridUpdating("updateRow", rowId, { version_no: version }); }
// Clear the temporary storage for this row (remove from pending updates) delete pendingVersionUpdate[rowId]; }, rowAdding: function (evt, ui) { // Generate a new ID based on timestamp let newGeneratedId = "ID-" + new Date().getTime(); // E.g., ID-1634456789234
// Set the new ID into the 'd3_process_id' ui.values["d3_process_id"] = newGeneratedId; if (!ui.values.id) { ui.values.id = Date.now(); // Or use a UUID if preferred } for (const key in ui.values) { if (ui.values[key] === null || ui.values[key] === undefined) { ui.values[key] = ""; } }
const location = ui.values.location_of_action_id ?? ""; const action = ui.values.action_id ?? ""; const allTransactions = $("#master_grid").igGrid("allTransactions");
// Exclude deleted rows from the duplicate check const deletedTransactions = allTransactions.filter(transaction => transaction.type === "deleterow");
// Get all d3_process_id values from deleted transactions const deletedProcessIds = deletedTransactions.map(transaction => transaction.rowId);
// Filter out active (non-deleted) transactions const activeTransactions = allTransactions.filter(transaction => transaction.type !== "deleterow");
// Check if the combination of location and action already exists in active (non-deleted) transactions const duplicateRow = activeTransactions.some(transaction => { const transactionRow = transaction.row || transaction; return ( transactionRow.location_of_action_id === location && transactionRow.action_id === action && !deletedProcessIds.includes(transactionRow.d3_process_id) // Exclude if d3_process_id from deleted rows exists ); });
if (duplicateRow) { fnShowCommonPopup('error', "Record already exists.", 'Error', function () { }); evt.preventDefault(); // Prevent the row from being added return; }
// Check for duplicates in the committed data (already in the grid) const gridData = data_ddl.action_details_data ?? $("#master_grid").igGrid("option", "dataSource"); // Get grid data const duplicateInGrid = gridData.find(row => row.location_of_action_id === location && row.action_id === action );
if (duplicateInGrid) { fnShowCommonPopup('error', "Record already exists.", 'Error', function () { }); evt.preventDefault(); // Prevent the row from being added return; } noRecordFoundCheckForGrid($('#master_grid')); // Generate version if both location and action are provided if (location && action) { ui.values.version_no = generateVersion(location, action); // Add version number to the row } } }, { name: "Sorting" } ]});
Please help me fix it.
I have been looking into your clarifications, and what I can say is that in order to display the column values as the dropdown’s item text and not code, I can suggest using the formatter option of the column.
Here can be found my sample for your reference.
Also, regarding showing/hiding the checkbox column, I have noticed that you have asked the same question in the following forum thread here. I will address the question there for better consistency and history tracking.
Let me know if you need any further information regarding the custom editor provider.
Yes , actually I have defined checkbox in a column. And i want this column to be hidden and only visible when grid is in edit mode like add/edit. And that column should be. Hidden rest of the time. And when that checkbox is checked during edit/add the dropdown should be there if unchecked then it should change to text box. And when it's a textbox it should come blanket by default. Also, the grid is now should display the text not the value/code of the dropdown.
Thank you for following up!
I have been looking into your clarifications, and the reason you have experienced these behaviors is because when checking/unchecking the checkbox, the combo and textbox visibility is toggled, however, the grid itself is not notified that the current editor has changed.
An approach I can suggest is to again define a custom global editorProvider variable, which is set to the instance of the editor inside the setValue function when the combo/textbox visibility is toggled. Inside this function, the this.currentEditor is set to either the combo or textbox, so it should be set again inside the valueChanging event of the checkbox, but this time using the global editorProvider variable that was defined and set earlier.
Here can be found a modified version of the sample.
Additionally, could you please clarify how the checkboxes should hide/show? I am asking this question because by default, the checkboxes are rendered only during editing/row adding.
Please test the sample on your side and let me know if you need any further information on the matter.