Author Topic: Customize attribute of save changes json object  (Read 1623 times)

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Customize attribute of save changes json object
« 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.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Customize attribute of save changes json object
« Reply #1 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

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: Customize attribute of save changes json object
« Reply #2 on: October 15, 2021, 05:05:55 pm »
That mean I have to add some code form every page.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Customize attribute of save changes json object
« Reply #3 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.

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: Customize attribute of save changes json object
« Reply #4 on: October 16, 2021, 04:57:32 am »
Thank you very much.

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: Customize attribute of save changes json object
« Reply #5 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' });
                    },
« Last Edit: October 18, 2021, 06:48:31 pm by hyh888 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Customize attribute of save changes json object
« Reply #6 on: October 18, 2021, 09:27:33 pm »
yes that one too.