Ignite UI version: 2018.2
When I set defaultValue in the iggrid initialization (columnSettings): works!When I change defaultValue in the rendered event: works!When I change defaultValue in the saveChanges event after committing the dataSource: doesn't workChanging another another parameter, f.e. "required" in the saveChanges event after committing the dataSource works too, so I suppose there's a problem changing defaultValue programmatically after initialization.
Is there a work around?
My code:
var grid = $("#CustomerStartupNormenGrid"); $.ajax({ type: "GET", cache: false, url: urlCustomerStartup_GetNormen, data: { klantNr: webCustomer.Klantnr, login: webUser.Gebruikersnaam, languageCode: languageCode }, dataType: "json", async: false, success(response, status, xhr) { if (response) { var ct = xhr.getResponseHeader("content-type") || ""; if (ct.indexOf("ERROR") === -1) { //Grid Initialization grid.igGrid({ language: languageCode.toLowerCase(), dataSource: response, responseDataKey: "OpstartNorm", updateUrl: urlCustomerStartup_SetNormen, autoGenerateColumns: false, primaryKey: "Volgnummer", autoCommit: true, width: "100%", height: "800px", columns: [ { headerText: "", key: "Volgnummer", dataType: "number", hidden: true }, { headerText: "", key: "Klantnr", dataType: "string", hidden: true }, { headerText: "", key: "Login", dataType: "object", hidden: true }, { headerText: "Afdelingscode", key: "Afdelingscode", dataType: "string" }, { headerText: "Artikelnr", key: "Artikelnr", dataType: "string" }, { headerText: "Telvolgorde", key: "Telvolgorde", dataType: "number" } ], features: [ { name: 'Updating', editMode: "dialog", rowEditDialogOptions: { width: "500px", height: "700px", }, columnSettings: [{ columnKey: "Klantnr", defaultValue: webCustomer.Klantnr }, { columnKey: "Login", defaultValue: [webUser.Gebruikersnaam] }, { columnKey: "Afdelingscode", required: true, editorType: 'combo', editorOptions: { mode: "dropdown", dataSource: response.Afdelingen, textKey: "Naam", valueKey: "Code" } }, { columnKey: "Artikelnr", required: true, editorType: 'combo', editorOptions: { mode: "dropdown", dataSource: response.Artikels, textKey: "Omschrijving", valueKey: "Artikelnr", validatorOptions: { language: languageCode.toLowerCase() } } }, { columnKey: "Telvolgorde", editorType: 'numeric', defaultValue: 0, required: true, allowSorting: true, currentSortDirection: 'ascending', editorOptions: { validatorOptions: { language: languageCode.toLowerCase() } } }], editRowEnded: function (evt, ui) { if (ui.update) { //ui.rowUpdate $("#CustomerStartupNormenGrid").igGrid("saveChanges", function (data) { if (data.ids.NewId > 0) { setTimeout(function () { grid.igGridUpdating("setCellValue", data.ids.OldId, "Volgnummer", data.ids.NewId); // Line 5 $( "#CustomerStartupNormenGrid > tbody > tr[data-id='" + data.ids.OldId + "']").attr("data-id", data.ids.NewId); // Line 6 }, 100); } grid.data("igGrid").dataSource.commit(); // Line 8 grid.data("igGrid").dataSource.allTransactions().length = 0; // Line 9 //Show feedback var message = TranslationDAL.localizedStrings["GridUpdated"][languageCode]; showFeedback("CustomerStartupNormenUpdatedMessage", message); CalcDefaultTelvolgorde(); }, function (jqXHR, textStatus, errorThrown) { alert(jqXHR.responseJSON.ErrorMessage); }); } }, rowDeleted: function (evt, ui) { var message = TranslationDAL.localizedStrings["GridUpdated"][languageCode]; showFeedback("CustomerStartupNormenUpdatedMessage", message); grid.igGrid("saveChanges"); CalcDefaultTelvolgorde(); }, generatePrimaryKeyValue: function (evt, ui) { ui.value = 0; } } ], rendered: function (evt, ui) { CalcDefaultTelvolgorde(); } }); } else { alert("ERROR:" + response); } } }, error(xhr, textStatus, errorThrown) { SharedFunctionsDAL.ShowUnexpectedError(xhr, errorThrown); } }); function CalcDefaultTelvolgorde() { var rowCount = grid.igGrid("rows").length; var columnSettings = grid.igGridUpdating("option", "columnSettings"); if (rowCount === 0) columnSettings[5].defaultValue = 0; else { var dataSource = grid.data("igGrid").dataSource; var lastCounter = dataSource._data[dataSource._data.length - 1].Telvolgorde; columnSettings[4].defaultValue = lastCounter + 10; } grid.igGridUpdating("option", "columnSettings", columnSettings); }
Thanks!
Hello Serge,
I am glad to hear that you managed to resolve the matter.
Thank you for using Infragistics.
Hello Martin,
Thanks for your sample! I was able to implement the workaround succesfully now. I had to use igNumericEditor in my case, because it's a column of dataType "number".
I have attached a sample where you can see how to implement the solution. The sample has a column "Name" and every time the dialog for editing or adding record is opened the default value is changed.This may help you to complete it on your side.
In case it doesn't help. I would appreciate if you could rearrange the my sample until the issue is reproduced. Then please send it back so I could investigate what causes the error. You can send yours instead.
Looking forward to hearing from you.
changingDefaultValueOfEditor.zip
Do you have any further help for me on this? I really need to get through this problem... Thanks!
I tried your solution, but I'm getting the following error when the dialog opens:
Uncaught Error: cannot call methods on igTextEditor prior to initialization; attempted to call method 'value' at Function.error (jquery-2.1.1.min.js:2) at HTMLInputElement.<anonymous> (jquery.mobile-1.4.5.js:927) at Function.each (jquery-2.1.1.min.js:2) at n.fn.init.each (jquery-2.1.1.min.js:2) at n.fn.init.a.fn.(anonymous function) [as igTextEditor] (localhost/.../jquery.mobile-1.4.5.min.js:3:10498) at HTMLTableElement.rowEditDialogAfterOpen (CustomerStartupDAL.ts:578) at a.(anonymous function).(anonymous function)._trigger (localhost/.../jquery.mobile-1.4.5.min.js:3:14553) at a.(anonymous function).(anonymous function)._dialogOpening (localhost/.../infragistics.ui.grid.updating.js:22:24032) at a.(anonymous function).(anonymous function)._dialogOpening (localhost/.../jquery.mobile-1.4.5.min.js:3:9626) at HTMLDivElement.f (jquery-2.1.1.min.js:2)