Grid destroy confirmation event to trigger ActionResult

4 posts, 0 answers
  1. Paul
    Paul avatar
    2 posts
    Member since:
    Sep 2016

    Posted 01 Nov Link to this post

    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
    }

  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 03 Nov Link to this post

    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.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Paul
    Paul avatar
    2 posts
    Member since:
    Sep 2016

    Posted 03 Nov Link to this post

    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.

  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 5 days and 11 hours ago Link to this post

    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.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready