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

Grid destroy confirmation event to trigger ActionResult

3 Answers 1020 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 01 Nov 2016, 07:53 PM

My aim is to delete the row when the Command Destroy column is clicked if the built in Confirmation popup if confirmed.

Want: Click Destroy Column > Confirm OK > ActionReult Triggered

Cannot use auto-sync since aiming at keeping other updates and inserts still require the save to be clicked to commit.

 

Currently the code will remove the row from the display when it is clicked as is built in.

And only after the save button for the grid is clicked does it trigger the ActionResult "OfficerDestroy" for doing so.

 

Seems there should be some event in this process that could trigger the ActionResult.

What are the options here for triggering that ActionResult while having a confirmation?

 

@(Html.Kendo().Grid<NexusPWI.ViewModels.Wizard.gridData>()
    .Name("OfficerGrid")
    .Columns(c => {
        c.Bound(vm => vm.GridId); //Can display for testing purposes
        c.Bound(vm => vm.FirstName).Width(50);
        c.Bound(vm => vm.LastName).Width(50);
        c.Bound(vm => vm.Title).Width(50);
        c.Command(command => { command.Destroy(); }).Width(30);
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Navigatable()
    .Pageable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Events(events => events.Error("officerGrid_error") // Handle the "error" event
            .RequestEnd("officerGrid_RequestEnd") // Handle the "RequestEnd" event
            .Change("officerGrid_Delete")
            )
        .Model(model => model.Id(vm => vm.GridId))
        .PageSize(1000)
        .Create("OfficerCreate", "Wizard")
        .Read("OfficerRead", "Wizard")
        .Update("OfficerUpdate", "Wizard")
        .Destroy("OfficerDestroy", "Wizard")//.AutoSync(true)
))

<script>

function officerGrid_RequestEnd(e) {
        if (e.type == "update" || e.type == "create") {
            this.read();
        }
    }
</script>


public ActionResult OfficerDestroy([DataSourceRequest] DataSourceRequest request, IEnumerable<gridData> models)
{//This code works fine
}

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 03 Nov 2016, 05:39 PM
Hello,

I suggest you go through this forum thread where my colleague Dimiter provided several options for achieving similar requirement. You can use built in Grid delete confirmation window, or disable it and display a custom confirmation window as described in the post below:
http://www.telerik.com/forums/confirm-modal-window-when-deleting-a-row-from-grid#p-f3cb6SrkaBsZviLrLNiQ

Regards,
Pavlina
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
0
Paul
Top achievements
Rank 1
answered on 03 Nov 2016, 08:20 PM

Looking at the examples it seems like:

The custom commands are only triggering in page script actions for changing the display and not an ActionResult in the controller.

And the one that has mention of ActionResult triggering is using the GridEditMode.InLine

 

Using the code reference examples I can make a custom command that removes a row from the displaying grid with a confirmation popup; though this is all on the display level and does not trigger the ActionResult.

 

Maybe I'm missing something but these examples do not seem to address how to:

Trigger an ActionResult using a confirmation in InCell mode.

0
Accepted
Pavlina
Telerik team
answered on 02 Dec 2016, 11:04 AM
Hi,

When using InCell edit mode, all of the changes will be send when Save Changes button is clicked. This is same for updating, creating as well as deleting records. Thus, when delete button is click the record is only marked as deleted, but the actual call to the server will happen when  the DataSource is sync by clicking on the Save Changes button.

Regards,
Pavlina
Telerik by Progress
Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Paul
Top achievements
Rank 1
Share this question
or