4
votes

I have a destroy command defined in one of the columns for a Kendo Grid:

columns: [
    {
        field: "Address",
        width: "200px"
    },
    {
        field: "City"
    },
    {
        field: "State",
        width: "40px"
    },
    {
        field: "Zip",
        width: "60px"
    },
    {
        field: "Active",
        width: "50px"
    },
    {
        command: ["edit", "destroy"],
        title: " ",
        width: "210px" 
    }
]

Editable is set to inline for the grid. Batch is set to true for the datasource.

Editing and saving works fine (all models are sent in JSON format to SAVE method).

But when I click on DELETE for one of the rows, it removes the row from the grid BUT it behaves just like I was saving all items. It calls the save method and sends every single row, except for the one I want to delete, in a JSON object.

The question is: Why is it not calling the destroy method?

Shouldn't it call the destroy method and send only the row being deleted?

Datasource definition:

dataSource: {
    error    : function (e) {
        CustomError(e);
    },
    type     : "json",
    transport: {
        read        : {
            contentType: "application/json; charset=utf-8",
            type       : "POST",
            url        : "../Services/svcPerson_Address.asmx/Search",
            dataType   : "json",
            cache      : false,
            complete   : function (e) {
                //alert(e);
            }
        },
        update      : {
            contentType: "application/json; charset=utf-8",
            type       : "POST",
            url        : "../Services/svcPerson_Address.asmx/Save",
            dataType   : "json",
            cache      : false,
            complete   : function (e) {
                if (typeof (e.responseText) != "undefined") {
                    var response = $.parseJSON(e.responseText);
                }
            }
        },
        destroy     : {
            contentType: "application/json; charset=utf-8",
            url        : "../Services/svcPerson_Address.asmx/Delete",
            type       : "POST",
            dataType   : "json",
            cache      : false,
            complete   : function (e) {
            }
        },
        create      : {
            contentType: "application/json; charset=utf-8",
            type       : "POST",
            url        : "../Services/svcPerson_Address.asmx/Save",
            cache      : false,
            complete   : function (e) {
                if (typeof (e.responseText) != "undefined") {
                    var response = $.parseJSON(e.responseText);
                }
            }
        },
        parameterMap: function (options, operation) {
            if (operation !== "read" && options.models) {
                return kendo.stringify({ models: options.models });
            }

            options.PersonId = 0;
            if (viewModel.SelectedPreceptor != null) {
                if (viewModel.SelectedPreceptor.PersonId != "" && viewModel.SelectedPreceptor.PersonId != null) {
                    options.PersonId = viewModel.SelectedPreceptor.PersonId;
                }
            }

            return kendo.stringify(options);
        }
    },
1
This is wierd! If I have more than one item in the grid and click on delete. THE FIRST item that I select to be deleted goes as SAVE, but if I keep deleting items they will go as DELETE. Question then is, why is the FIRST item I try to delete going as SAVE? - Naner
The problem was the id property inside schema. I had it in there, but the name was wrong. It fixed the delete problem and also an issue with click on cancel and the row disappearing. Thanks anyway. - Naner

1 Answers

5
votes

I had the same problem: The wrong id was set in the model.

My code was:

model: {
    id: "Id",
    fields: {
        UserId: { editable: false },
        ....

but should have been:

model: {
    id: "UserId",
    fields: {
        UserId: { editable: false },
        ....