AddNewRecord button No Postback in batch mode

1 Answer 22 Views
Grid
Mark
Top achievements
Rank 1
Iron
Mark asked on 14 Jan 2022, 09:03 PM

My Radgrid is in EditMode="Batch" . When I click on the AddNewRecord I need to create a record in the DB. The ItemCommand event does not fire. 

 

Is there a way to get it to fire.

I did see this? https://stackoverflow.com/questions/31816599/overriding-the-telerik-radgrid-addnewrecordbutton-functionality-to-redirect-the 

Is there a better way to do it so the batch mode stays intact? 

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 19 Jan 2022, 09:36 AM

Hi Mark,

BatchEdit is a Client-Side (JavaScript-based) editing functionality of RadGrid. Everything you do (create rows, delete, update) happens on the client. The only Server-Side event that is fired is the batcheditcommand, when you click on "Save Changes", see https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/server-side-programming/events/batcheditcommand

To interact with the BatchEdit manager, you can take advantage of the Batch Editing Client-side API - https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/edit-mode/batch-editing/client-side-api

You can find more specific information about the BatchEdit functionality in the following article: RadGrid Batch Editing Templates and Specifics -  https://docs.telerik.com/devtools/aspnet-ajax/knowledge-base/grid-batch-editing-templates-and-specifics

If you rather prefer to work on the Server-Side with the Grid, you can use any EditMode except Batch.

Here is an InPlace EditMode example that you might like: Update all, individual or selected rows using RadGrid with InPlace edit mode - https://docs.telerik.com/devtools/aspnet-ajax/knowledge-base/grid-update-all-individual-or-selected-rows-using-inplace-edit-mode

 

Regards,
Attila Antal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Mark
Top achievements
Rank 1
Iron
commented on 25 Jan 2022, 07:17 PM

So how would a wire into the addNewRecord event from the Batch Editing Client-side API methods?

Attila Antal
Telerik team
commented on 26 Jan 2022, 04:09 PM

If you want to subscribe to the event that will trigger when clicking on "Add New Record" in BatchEdit mode, you will need to use the OnBatchEditOpened event:

In the event handler, a newly created row will have a negative row index in its ID attribute since it does not exist in the database. You can use that information and set up a condition that will check for the ID ending with -1, to distinguish the Add New Record Vs. editing an existing row.

function OnBatchEditOpened(sender, args) {
    var editedRowElement = args.get_row();

    if (editedRowElement.id.endsWith("-1")) {
        // Creating a New Row
    } else {
        // Editing an existing Row
    }
}

Mark
Top achievements
Rank 1
Iron
commented on 27 Jan 2022, 02:47 PM

That did the trick. Thanks!

 


  function OnBatchEditOpened(sender, args) {
                var editedRowElement = args.get_row();
                if (editedRowElement.id.endsWith("-1")) {
                    PageMethods.AddRow();
                    var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                    masterTable.rebind();
                } else {
                    // Editing an existing Row
                }
            } 

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Iron
Answers by
Attila Antal
Telerik team
Share this question
or