hasChanges() breaking batch edit Deletes

4 posts, 0 answers
  1. CDK
    CDK avatar
    9 posts
    Member since:
    Feb 2019

    Posted 02 Jan Link to this post

    I am implementing a RadGrid with batch mode editing using clientside binding with a RadClientDataSource.   I am finding that calling .hasChanges() results in records flagged for Delete to not actually get deleted when .saveChanges() executes.

     

    This is my setup: 

    I created my own button for saving,  as such:

    <CommandItemTemplate>
                 <telerik:RadButton  ID="RadButtonSave" runat="server" Text="Save" CssClass="GoButton" AutoPostBack="false" OnClientClicked="function(){ saveChanges();}" >
                </telerik:RadButton>
    </CommandItemTemplate>

     

    Which calls the following javascript function:

     

    function saveChanges() {
      var grid = $find("<%= RadGrid1.ClientID %>");
      //var isDirty = grid.get_batchEditingManager().hasChanges(grid.get_masterTableView());
      grid.get_batchEditingManager().saveChanges(grid.get_masterTableView());
    }

    If I make changes to grid data and click the Save button the webservices for the insert, update, delete are being called.

    HOWEVER, if I uncomment the "var isDirty...." line in the above .saveChanges() function that calls .hasChanges(),  then the Deletes will no longer save.   The web service for deletes simply does not get called. Inserts and update still work correctly.   If i comment out that line, then the deletes work again.

     

    I found the same behaviour on a LiveDemo example that checks .hasChanges().

    https://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/client-data-source-binding/defaultcs.aspx

    Steps to reproduce:

    - Make any change to the first record, such as modifying the Contact Name.

    - On the second record, Click the "x" under the DELETE column to mark it for delete.

    - Click any column heading to sort.  (This calls a UserAction event handler that calls .hasChanges())

    - Choose to Cancel at the popup prompt.

    - Click "Save changes".

    - Monitor the browser console, you will find that webservice UpdateCustomers is called,  but DeleteCustomers is not.

     

    Please confirm whether this is a bug and if there is a workaround.

     

  2. Attila Antal
    Admin
    Attila Antal avatar
    575 posts

    Posted 07 Jan Link to this post

    Hello,

    Thank you for your time reporting this problem.

    We have tested the scenario you described and we can confirm this is a bug in the component. I have created a Bug report on your behalf and can be accessed by visiting the following link: hasChanges() method clears flags for deleting records. I have also shared a workaround on that page, and try using it until a fix is delivered to address this problem.

    As a token of gratitude for reporting this issue I have updated your Telerik points.

    Please excuse us for any inconvenience this may have caused.

    Kind regards,
    Attila Antal
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. CDK
    CDK avatar
    9 posts
    Member since:
    Feb 2019

    Posted 07 Jan in reply to Attila Antal Link to this post

    Thanks for the suggestions, but the proposed workarounds also appear to have some problems...

     

    return Object.keys(grid.get_batchEditingManager()._changes).length > 0

     

    Using this method works without breaking any of the web service calls.  However, it does not reset after saveChanges(), so once true it remains true.     I would have thought saveChanges would reset _changes.  Is there something else to trigger the reset?  I worked around it with an OnRequestEnd eventhandler for my ClientDataSource where I manually clear it, and it now seems to work reliably.  But not sure what side-effects that could have.

    var grid = $find("<%= RadGrid1.ClientID %>");
    grid.get_batchEditingManager()._changes = {};

     

     

     

     

    return grid.get_batchEditingManager()._extractChangesString(grid.get_masterTableView()).length > 0;

    Using the above still causes Delete webservice to not be called, but now additionally the Insert webservice is not called either.







  4. Attila Antal
    Admin
    Attila Antal avatar
    575 posts

    Posted 13 Feb Link to this post

    Hello,

    We have made several tests using the method below and seems to be working in most of the cases.

    function hasChanges(grid) {
        return grid.get_batchEditingManager()._extractChangesString(grid.get_masterTableView()).length > 0;
    }

    Attached you can find the sample project I've used for testing this scenario.

    Kind regards,
    Attila Antal
    Progress Telerik

    Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
Back to Top