Telerik RadGrid Batch Mode

2 Answers 17 Views
Grid
Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
Rakhee asked on 11 Jun 2025, 08:40 AM | edited on 11 Jun 2025, 08:41 AM

Hi

Im using visual studio 2019 .netframework using c#

I have a telerik Rad grid that is in Batch Mode and works great.  Within rg_SalesPlan_BatchEditCommand it goes through each edited row and does an update to the database, if one of the records fails to update the error message is added to a variable which collects any other errors. One finished in the foreach loop if any errors occured a popup alert is displayed with the errors.

My problem is once I click OK to the alert to acknowledge the errors, the grid refreshes but Im unable to continue editing any other rows, If I click on  a row nothing happen, until I click on Cancel or Save Changes button, then the grid goes back to normal.

Whats the best way to refresh the state of the grid so its back to normal please? 

Thanks

Rakhee

Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
commented on 11 Jun 2025, 09:03 AM

Or Programmatically run Cancel Changes button

2 Answers, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 16 Jun 2025, 05:03 AM

Hi Rakhee,

To refresh the state of the RadGrid and ensure it returns to normal functionality after acknowledging the errors, you can programmatically trigger the "Cancel Changes" functionality. This approach will reset the grid's state and allow further editing. Here's a concise solution:

You can use JavaScript to simulate the "Cancel Changes" action, which effectively resets the grid state:

  1. Invoke Cancel Changes Programmatically: Utilize the cancelAllChanges() method of the grid's batch editing manager to reset the grid state. 
    function resetGridState() {
        let grid = $find('<%=RadGrid1.ClientID%>');
        let masterTable = grid.get_masterTableView();
        let batchManager = grid.get_batchEditingManager();
    
        batchManager.cancelAllChanges(masterTable);
    }
    
    function showAlertAndReset(errors) {
        alert(errors);
        resetGridState();
    }
    
  1. Trigger the Function: Call the showAlertAndReset() function with the error message when necessary:
protected void rg_SalesPlan_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
    string errorMessages = ""; // Collect error messages here

    foreach (var command in e.Commands)
    {
        // Your logic to process each command and collect errors
    }

    if (!string.IsNullOrEmpty(errorMessages))
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "showAlert", "showAlertAndReset('" + errorMessages + "');", true);
    }
}
  • JavaScript Function: The resetGridState() function uses the batch editing manager's cancelAllChanges() method to cancel all changes and refresh the grid state.
  • Alert and Reset: The showAlertAndReset() function displays the error alert and then resets the grid state.
  • Server-side Integration: Use ScriptManager.RegisterStartupScript to call the JavaScript function from the server-side event handler.

    This approach should help in restoring the grid to its editable state after handling errors. Please refer to the following articles for additional information:

    Regards,
    Vasko
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    Rakhee
    Top achievements
    Rank 1
    Iron
    Iron
    Iron
    commented on 17 Jun 2025, 08:14 AM

    Thank you for your response

    I don't need the errors now as I have handled them a different way, the issue with the grid becoming uneditable seems to happen on a refresh of the page. So when I click on the display button the Grid becomes uneditable.

    So within btnDisplay method I have added the script just for the resetGridState but it doesnt put the grid back to normal state

    here is my code

    and Javascript

    function resetGridState() {
                debugger;
                let grid = $find('<%=rg_SalesPlan.ClientID%>');
                let masterTable = grid.get_masterTableView();
                let batchManager = grid.get_batchEditingManager();

                batchManager.cancelAllChanges(masterTable);
            }

     

    Rakhee
    Top achievements
    Rank 1
    Iron
    Iron
    Iron
    commented on 17 Jun 2025, 09:34 AM | edited

    Ok I found the issue why the grid is disabled when click on Display, the RadAjaxManager is causing the problem. I have the following code:

    <tlk:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <ClientEvents OnRequestStart="onRequestStart" />
                <AjaxSettings>
                    <tlk:AjaxSetting AjaxControlID="rg_SalesPlan">
                        <UpdatedControls>
                            <tlk:AjaxUpdatedControl ControlID="rg_SalesPlan" />
                        </UpdatedControls>
                    </tlk:AjaxSetting>
                </AjaxSettings>
            </tlk:RadAjaxManager>

     

    function onRequestStart(sender, args) {
                if (args.get_eventTarget().indexOf("ExportToExcel") >= 0)
                    setTimeout(removePanel, 3000);
                args.set_enableAjax(false);
                $(".applicationMenu").text("ApplicationTest");            
            }

     

    If I remove this code, the grid becomes editable after refresh, this code is used so the export to excel button on the radgrid works.

    Thanks

     

    0
    Rakhee
    Top achievements
    Rank 1
    Iron
    Iron
    Iron
    answered on 18 Jun 2025, 07:45 AM
    Found this issue that was causing the problem, the RadAjaxManager I had for exporting to excel. I removed the updatedControls section and everything seems to work ok now
    Vasko
    Telerik team
    commented on 18 Jun 2025, 08:27 AM

    Hi Rakhee,

    I am glad you have found the issue with the problem. I will close the ticket for now but feel free to revisit it if there are still issues related to this.

    Regards,
    Vasko
    Progress Telerik
    Tags
    Grid
    Asked by
    Rakhee
    Top achievements
    Rank 1
    Iron
    Iron
    Iron
    Answers by
    Vasko
    Telerik team
    Rakhee
    Top achievements
    Rank 1
    Iron
    Iron
    Iron
    Share this question
    or