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

RadGrid in batch edit mode force un focus when clicking away

6 Answers 342 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Stacey
Top achievements
Rank 1
David Stacey asked on 31 Jul 2014, 02:28 PM
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


6 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 05 Aug 2014, 09:55 AM
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.

 
0
David Stacey
Top achievements
Rank 1
answered on 05 Aug 2014, 12:29 PM
Thank you,

The batchEditingManager._tryCloseEdits(document.body);
was the function which i needed.
All works fine now.
0
Abhisesh
Top achievements
Rank 1
answered on 19 Feb 2020, 08:55 AM

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.

0
Peter Milchev
Telerik team
answered on 21 Feb 2020, 09:03 AM

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.
0
Gerald
Top achievements
Rank 1
answered on 06 Oct 2020, 03:54 PM

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.

0
Doncho
Telerik team
answered on 09 Oct 2020, 03:32 PM

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).

Tags
Grid
Asked by
David Stacey
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
David Stacey
Top achievements
Rank 1
Abhisesh
Top achievements
Rank 1
Peter Milchev
Telerik team
Gerald
Top achievements
Rank 1
Doncho
Telerik team
Share this question
or