RadGrid in batch edit mode force un focus when clicking away

7 posts, 0 answers
  1. David Stacey
    David Stacey avatar
    14 posts
    Member since:
    May 2010

    Posted 31 Jul 2014 Link to this post

    Hi,

    I have a radgrid in batch edit mode inside a RadDock control.
    I have a save button (dockcommand) outside of the grid which calls the save
    function of the grid using the OnClientCommand and a javascript function.
    If i edit a cell in the grid and then click of the cell (anywhere on the page)
    the cell loses focus and the innerGrid.get_batchEditingManager()._changes
    is updated. Clicking the save button works correctly.

    The problem is if a user edits a cell and then clicks the save button (without
    clicking anywhere else first) the cell is still in edit mode and the save has
    nothing to save.

    How do i get the edit cell to loss focus and come out of edit when clicking on
    the save button?

    All this is done clientside. The radgrid is wrapped within our own control
    which implements a save function


  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2491 posts

    Posted 05 Aug 2014 Link to this post

    Hello,

    For your convenience I have prepared a sample project where the functionality is implemented. You could find it attached to this post. The RadGrid is placed in a RadDock and a custom DockCommand is used to save changes in the grid.

    Try using similar approach and you should be able to implement the functionality you are looking for.

    Regards,
    Viktor Tachev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. David Stacey
    David Stacey avatar
    14 posts
    Member since:
    May 2010

    Posted 05 Aug 2014 in reply to Viktor Tachev Link to this post

    Thank you,

    The batchEditingManager._tryCloseEdits(document.body);
    was the function which i needed.
    All works fine now.
  4. Abhisesh
    Abhisesh avatar
    1 posts
    Member since:
    Dec 2011

    Posted 19 Feb in reply to Viktor Tachev Link to this post

    I am having a similar situation and I have made changes as per your code.I have 4 columns in a grid and when batchEditingManager._tryCloseEdits(document.body); executes it tries to create 4 request (each for cells). But whenever these 4 requests are on the way,  batchEditingManager.saveChanges(masterTableView); execute another request before completing the prev. requests such that some of the values are not being updated when I see on   RadGrid1_UpdateCommand editItem. 

    How to wait for all cells re.quest to get completed before saveChanges request fires.

  5. Peter Milchev
    Admin
    Peter Milchev avatar
    857 posts

    Posted 21 Feb Link to this post

    Hello Abhisesh,

    If the editors' close takes a bit more time, indeed the save changes logic might be executed before all the editors are closed and the cell values updated.

    That is why I would suggest applying a timeout before triggering the saveChanges:

    <script type="text/javascript">
        function saveData(sender, args) {
            var grid = $find("<%= RadGrid1.ClientID %>");
            var masterTableView = grid.get_masterTableView();
            var batchEditingManager = grid.get_batchEditingManager();
            batchEditingManager._tryCloseEdits(document.body);
            setTimeout(function () {
                batchEditingManager.saveChanges(masterTableView);
            }, 10)
        }
    </script>

    Regards,
    Peter Milchev
    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.
  6. Gerald
    Gerald avatar
    1 posts
    Member since:
    Feb 2016

    Posted 06 Oct in reply to Peter Milchev Link to this post

    I'm having the same issue and this code does not work in my case. I require the OnBatchEditCellValueChanged event to be raised before the save routine is run.

    It appears to work the first time editing the cell and then clicking the external save button. But I have validation code that runs first and if the validation fails the save is not completed. When the user makes corrections and click save again the OnBatchEditCellValueChanged event is never raised and the additional cells that are updated in this event are not updated and the original cell being edited remains in edit mode.

  7. Doncho
    Admin
    Doncho avatar
    72 posts

    Posted 09 Oct Link to this post

    Hi Gerald,

    You can try to call the saveChanges method after validating the page:

    function saveData(sender, args) {
        var grid = $find("<%= RadGrid1.ClientID %>");
        var masterTableView = grid.get_masterTableView();
        var batchEditingManager = grid.get_batchEditingManager();
        batchEditingManager._tryCloseEdits(document.body);
        if (Page_ClientValidate()) {
            batchEditingManager.saveChanges(masterTableView);
        }
    }
    In case this is not helping, we would need to seed more details of the concrete scenario in order to help. Please isolate a runnable sample project replicating the problem you and share it with us in a formal support ticket. So we can have an overview of the current structure and be able to inspect it locally, see Isolating a problem in a sample project.
    It would also be useful if you modify the sample shared by Viktor earlier in this forum to reproduce the problem and send it for troubleshooting

     

    Looking forward to your feedback!

    Regards,
    Doncho
    Progress Telerik

    Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Back to Top