I'm creating a grid as given below.
this.resources is the array containing the data. My expectation is that the data source will update accordingly with row additions, deletions and edits in the grid control. Adding rows definitely updates the data source. However, editing DOES NOT. I'm capturing the edit events through "actionComplete" and inspect the source array afterwards which clearly shows the data source is not changed even though the grid shows a change.
I can do a workaround by capturing the edited row in the actionCompelte event and forcing an update on the data source. however, I doubt if that is the way to do it.
Will apprecaite any assistance on this matter.
|
// Grid’s actionComplete event handler
function actionComplete(args: any): void {
if (args.requestType === 'save') {
var updatedData = grid.dataSource;
console.log(updatedData);
}
} |
Good day,
Thanks for the assistance. I compared the solution to what I'm doing, and it seems like this only works if there is a primary key (remove the primary key in your solution and you will see it does not work). If the primary key is removed, then no updates are reflected in the dataSource property; Why is this the case ?
If this is the only way, is it possible to automatically assign a primary key id and not having the user to do it ? My use case will be a problem if the user has to manually enter a primary key id.
UPDATE:
Adding isIdentity:true to the id column seems to be doing the trick. However, the id value is always set as "undefined". So I don't really understand what's happening in the background. I need to save the data on the server and load it again. Saving the ids as "undefined" I think will cause problems when I load them again to the grid.
|
// Grid’s actionBegin event handler
function actionBegin(args: any): void {
if (args.requestType === 'save' && args.action === 'add') {
// Condition executes on performing add save action
// A new primary key value is assigned to the primary key data field
// Here we have generated a random number for demonstrating this case to you, so please ensure the primary key value set is a unique value
args.data.OrderID = parseInt((Math.random() * 1000).toString());
}
} |
|
{ field: 'OrderID', isPrimaryKey: true, visible: false } |
Thanks, I guess a random id can work. However, I've done the following for TreeGrid which increments the id. It was a bit challenging due to children tasks.
By the way, referencing args.data on TreeGrid does not update the source data. It only works with Grid. Thus I had to do a workaround to access the data source directly.
HI there,
Note that I think there are issues using TreeGrid, Grid and Gantt on the same page. I have created a new issue regarding this. I have found a workaround using the Gantt instread of TreeGrid so I'm fine for now thanks .