Hi
I don't want to use the generated ID because it is wrong most of the times. I have the ASP.NET api returning the created ID and want to update it in the grid afterwards.
editCellStarted = function (evt, ui) { if (ui.rowAdding && ui.columnKey === 'ID') { ui.editor.igEditor("value", -1); }};
The code above works fine, although I don't know if this is the right way to do it.
Using the following code I try to update the ID to the value returned via the AJAX call.
$("#grid1").igGridUpdating("setCellValue", ui.rowID, "ID", data);
It does actually work, but in the console the following error appears: "TypeError: can't convert null to object". Changing another value (string/currency value) works fine.
Is there a work around or something to solve this?
Looked into it again today and fixed it with a work around:
Instead of rowAdded I now listen to rowAdding I invoke another function which does a AJAX post to the server, waits for the new ID to return and updates it in the JSON. Then I push the JSON value in the viewModel datasource:
ui.values.ID = data;booksModel.books.push(ui.values);
I let the rowAdding function return false, so the default behavior is blocked.
I looked more into this issue, and it seems it gives the error because the new row isn't added to the Knockout datasource. I noticed when I tried to get a cell value after adding a row. So I checked my Knockout model and it only contains the records that were already there, not the one I added just before.
I have got autoCommit enabled on my grid, so why isn't it adding the rows to the knockout model? Do I have to do this manually?
EDIT:
I tried adding the record to the Knockout model like so:
booksModel.books.push(ui.values);
After that I log the model to check if the new row with ID -1 is in there (it is):
console.log(ko.toJS(booksModel.books));
And then I try editting the ID, ui.rowID are set and correct (logged those to):
Still giving an error:
...s.responseDataKey]){c=c[this.settings.responseDataKey]}if(e){for(d=0;d<c.length;...
Using setCellValue on the datasource results in the same error:
code:
ds.setCellValue(22, "ID", 25, true);
error: