Author Topic: IsDirty/rollback when using "option", "dataModel.data" to load the grid  (Read 2845 times)

mshapiro

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 35
    • View Profile
I have "track: true" as a grid option and I am populating the grid with JSON data.  If I include dataModel as part of the grid object definition then everything works as expected and I can use rollback to undo edits.  If I populate the data using $grid.pqGrid("option", "dataModel.data", response.data) after the grid is created , then edits do not make the grid dirty and rollback has no effect.  I've tried various combinations of commit and refresh with no success.  How can I use isDirty and rollback if I load dataModel.data after the grid is created?  Thank you.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: IsDirty/rollback when using "option", "dataModel.data" to load the grid
« Reply #1 on: January 29, 2015, 09:51:02 pm »
IsDirty/ Rollback is not dependent upon how you load data into the grid.

If you populate the data using $grid.pqGrid("option", "dataModel.data", response.data) after the grid is created, you have to set

1) dataModel.location = "local" initially.

and

call refreshDataAndView when you set data.

Code: [Select]
     $.ajax({
            url: "/pro/products/get",
            dataType: 'json',
            success: function (response) {
                debugger;
                $grid.pqGrid("option", "dataModel.data", response.data)
                    .pqGrid("refreshDataAndView");
            }
     });

Please use trackModel: { on: true }, //to turn on the track changes instead of track: true
« Last Edit: January 29, 2015, 09:53:54 pm by paramquery »

mshapiro

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: IsDirty/rollback when using "option", "dataModel.data" to load the grid
« Reply #2 on: January 30, 2015, 03:08:42 am »
It's working now.  I discovered that not only is setting dataModel.location = "local" initially a requirement, dataModel.recIndx also has to be set initially.  Thank you.