ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: hyh888 on October 15, 2021, 07:44:45 am

Title: Customize attribute of save changes json object
Post by: hyh888 on October 15, 2021, 07:44:45 am
the json object structure of sava change is
list: {
    addList: [{id: 1000, field1: value1, field2, value2,...}, {id: 1001, field1: value1, field1: value2}, ...],
    deleteList: [{id: 10}, {id: 29},....],
    updateList: [{id: 3, field1: value1, field2, value2,...}, {id: 7, field1: value1, field1: value2}, ...]
}

but the structure of our company is something like:
items: {
    insert: [{id: 1000, field1: value1, field2, value2,...}, {id: 1001, field1: value1, field1: value2}, ...],
    delete: [{id: 10}, {id: 29},....],
    update: [{id: 3, field1: value1, field2, value2,...}, {id: 7, field1: value1, field1: value2}, ...]
}

If pqgrid has provided the function of json obj attribute customization function? Else I have to manually change json attribute in every crud page, it wil be a big trouble for me.
Title: Re: Customize attribute of save changes json object
Post by: paramvir on October 15, 2021, 03:30:39 pm
Before sending save data through remote call, items can be used instead of list and other gridChanges object keys can be named appropriately.

var gridChanges = grid.getChanges({ format: 'byVal' });
gridChanges.insert = gridChanges.addList;
delete gridChanges.addList;
//do same for other 2 keys.

https://paramquery.com/pro/demos/editing_batch
Title: Re: Customize attribute of save changes json object
Post by: hyh888 on October 15, 2021, 05:05:55 pm
That mean I have to add some code form every page.
Title: Re: Customize attribute of save changes json object
Post by: paramvir on October 15, 2021, 06:33:10 pm
No, you have to make changes in saveChanges function only. Then keep this function in a separate file and call that function from every crud page.
Title: Re: Customize attribute of save changes json object
Post by: hyh888 on October 16, 2021, 04:57:32 am
Thank you very much.
Title: Re: Customize attribute of save changes json object
Post by: hyh888 on October 18, 2021, 05:01:41 pm
if I change attribute of pqGrid Json like you showed, should I changed the following code in sample?

                    success: function (changes) {
                        //debugger;
                        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: Customize attribute of save changes json object
Post by: paramvir on October 18, 2021, 09:27:33 pm
yes that one too.