This is a migrated thread and some comments may be shown as answers.

kendo.data.DataSource.hasChanges() method true after save

3 Answers 1323 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Iron
Mark asked on 06 Jan 2017, 08:30 PM

I've configured my kendo grid to call a custom service upon clicking "Save Changes" button.  Function call is as follows:

saveChanges: function (e) {
 
    e.preventDefault();
    $scope.updateLineItems(e);
 
    // Clear red triangles on edited cells
    $scope.grid.refresh();
},

 

Does calling preventDefault() prevent the grid from resetting the return value of hasChanges()?  When I make a change the value is true.  I was hoping that after clicking "Save Changes" it would revert to false, but it does not.  I tried adding a line after the grid refresh to manually run the cancelChanges() method, but that undid the changes in the grid display.

Is there any other method to take the grid out of edit mode?

Thanks in advance

 

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 10 Jan 2017, 10:21 AM

Hello Mark,

As stated in the saveChanges article the e.preventDefault method will not call the sync method of the data source. The hasChanges method will still return true if there are some changes made to the DataSource. Indeed the cancelChanges will remove all changes made to the gird. Could you please clarify what you are trying to achieve? 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mark
Top achievements
Rank 1
Iron
answered on 10 Jan 2017, 01:04 PM
Boyan,

Thank you for responding.

My grid always contains data but the user has the ability to edit the existing data and to add rows.  Adding rows does not add a blank row that they can then fill in.  Upon adding a row I make a call to a service that creates a new database record which copies the data from the last row in the grid.  I then refresh the dataSource to show the newly created row(s).

I'm using the transport.read event on my datasource but I have a custom method I'm using for updates, thus the e.preventDefault().  When the user clicks the button to create additional rows, I'm checking the hasChanges() method to ensure there are no pending updates.  If the application adds rows while there are pending updates in any existing records, the updates are lost due to the refresh I must run to pull the new rows from the database.

Here is how I was hoping to use the hasChanges method:

- User updates data in the grid
- User clicks to add rows (hasChanges() method returns true)
- Message box appears "There are pending updates in the grid
- Please save or cancel your changes before adding new rows"
- User clicks "Save Changes" or "Cancel Changes" button
- User is then able to add rows (here is where hasChanges() is still true)

I hope this answers your question.  Any insight you could provide on how I could work around this issue would be appreciated.  Thank you
0
Boyan Dimitrov
Telerik team
answered on 12 Jan 2017, 10:19 AM

Hello Mark,

Something I do not quite understand is why in the saveChanges event handler e.preventDefault(); is being called. If save changes is not prevented it should sync the DataSource with the server and then hasChanges should return the correct result. 

In order words: 

   - there are some changes made to the existing items (hasChanges returns true). 

   - user tries to add a new row, but hasChanges returns true (there are pending changes). 

    - following the instructions from the message box user saves changes or cancels them. (no preventing in the save changes). 

    - dataSource is synced with the server and hasChanges should return false if user tries to add new row. 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Iron
Answers by
Boyan Dimitrov
Telerik team
Mark
Top achievements
Rank 1
Iron
Share this question
or