ParamQuery grid support forum

General Category => ParamQuery Pro Evaluation Support => Topic started by: cmcooper on September 17, 2016, 12:54:23 am

Title: When is the grid data actually changed after commit()?
Post by: cmcooper on September 17, 2016, 12:54:23 am
I'm trying to implement saving of nested grids when the parent grid is saved. The parent row has an identity column that is generated by the db. This column is also a foreign key in the nested grid rows, so I need the value before saving the nested grid. At what point after calling commit() on the parent grid will the identity be populated in the parent row?

Code: [Select]
function saveChanges(){
            //attempt to save editing cell.
            if (grid.saveEditCell() === false) {
                return false;
            }

            if (grid.isDirty() && grid.isValidChange({ focusInvalid: true }).valid) {

                var changes = grid.getChanges({ format: 'byVal' });

                // Save changes to db
                $.ajax({
                    dataType: "json",
                    type: "POST",
                    async: false,
                    beforeSend: function (jqXHR, settings) {
                        grid.showLoading();
                    },
                    url: "SaveChanges",
                    data: { strChanges: JSON.stringify(changes) },
                    success: function (changes) {
                        grid.commit({ type: 'add', rows: changes.addList });
                        grid.commit({ type: 'update', rows: changes.updateList });
                        grid.commit({ type: 'delete', rows: changes.deleteList });

                        grid.history({ method: 'reset' });
                    },
                    complete: function () {
                        grid.hideLoading();
                    }
                });
            }
        }
Title: Re: When is the grid data actually changed after commit()?
Post by: paramvir on September 17, 2016, 08:57:14 am
commit() is a synchronous method, so id of the parent row is populated just after call to commit() method.
Title: Re: When is the grid data actually changed after commit()?
Post by: cmcooper on September 19, 2016, 05:24:31 pm
After the calls to commit() above, pdata still does not have the ID populated for new rows. Additionally, I have a saveChanges method on the detail grid.

Code: [Select]
saveChanges: function (thisGrid) {
                    DoSomething(rowData.ID, thisGrid);
                },

When this is called after the call to commit() on the parent grid, rowData.ID is still undefined for new rows.
Title: Re: When is the grid data actually changed after commit()?
Post by: paramvir on September 19, 2016, 10:10:11 pm
You need to check the value of id in changes.addList in the success callback. If it's not there, you need to correct remote script to add id of new rows.

Code: [Select]
success: function (changes) {
  //check whether changes.addList contain id of rows.
                        grid.commit({ type: 'add', rows: changes.addList });
                        grid.commit({ type: 'update', rows: changes.updateList });
                        grid.commit({ type: 'delete', rows: changes.deleteList });

                        grid.history({ method: 'reset' });
                    },
Title: Re: When is the grid data actually changed after commit()?
Post by: cmcooper on September 20, 2016, 01:14:00 am
There were actually two issues here.

1. I changed
Code: [Select]
return js.Serialize(dlist);
to
Code: [Select]
return JsonConvert.SerializeObject(dlist, new Newtonsoft.Json.Converters.IsoDateTimeConverter() { DateTimeFormat = "MM/dd/yyyy" });in the SaveChanges() method in the controller.

2. I had to hide the detail column while committing.