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
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.
The batchEditingManager._tryCloseEdits(document.body);
was the function which i needed.
All works fine now.
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.
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
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.
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);
}
}
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).