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

Specify parameters to 'destroy' method?

2 Answers 553 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 04 Jun 2012, 07:04 PM
I have a KendoGrid setup with the following:

    var gridDataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "/api/Group/Members",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8"
                },
                destroy: {
                    url: "/api/Group/DeleteMember",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8"
                }
            },
            schema: {
                model: {
                    id: "entityId",
                    fields: {
                        iconURL: { type: "string" },
                        entityName: { type: "string", editable: false },
                        entityId: { type: "string" }
                    } // End of fields
                } // End of model
            }
        });

When I click 'delete' on a grid item, I see the following call made:
DeleteMember?entityId=myId&entityName=name&iconURL=icon%2F%3Fid%3D5894%26s%3D16

Is there a way to add another parameter to the delete call (a parameter that is not a member of the dataSource)?

2 Answers, 1 is accepted

Sort by
0
Accepted
Jerry T.
Top achievements
Rank 1
answered on 04 Jun 2012, 07:38 PM
Kyle,

Try something like this:

        this.itemsDataSource = new kendo.data.DataSource({
            transport: {
                create: {
                    type: "POST",
                    url: "../Services/Js/Service_Js.svc/InsertItem",
                    contentType: "application/json; charset=utf-8",
                    dataType: "jsonp"
                },
                read: {
                    type: "POST",
                    url: "../Services/Js/Service_Js.svc/GetItems",
                    contentType: "application/json; charset=utf-8",
                    complete: function(e) {
                        me.addItems(me.itemsDataSource._data);
                    }
                },
                update: {
                    type: "POST",
                    url: "../Services/Js/Service_Js.svc/UpdateItem",
                    contentType: "application/json; charset=utf-8",
                    dataType: "jsonp"
                },
                destroy: {
                    type: "POST",
                    url: "../Services/Js/CostingSheetService_Js.svc/DeleteItem",
                    contentType: "application/json; charset=utf-8"
                },
                parameterMap: function(options, operation) {
                    switch (operation)
                    {
                        case "read":
                            return JSON.stringify(options);
                            break;

                        case "create":
                        case "update":
                        case "destroy":
                            return JSON.stringify({ item: options, source: "Favorite", status: "B" });
                            break;
                    }
                }
            },
            schema: {
                data: "d",
*snipped*

Just be sure that the parameter names in the object being "stringified" match your service's parameters' names.

Jerry

Daniel
Top achievements
Rank 1
commented on 02 May 2021, 11:39 PM

Hi Jerry, I saw this thread and figured you might be able to help me with something...I am trying to call 2 ajax calls through the kendo grid destroy method in order to delete the same item from 2 different sharepoint lists. I have the first ajax call deleting the grid item successfully from the page, and when calling the 2nd ajax call -- it fails and gives me a 404 saying the item can't be found. This is because the same item on the 2nd list doesn't have the same ID on the 2nd list as it does on the first. But when I console.log(options) in the destroy command, it only gives me information for the item from the first list. I can't seem to access the information for the 2nd sharepoint list so that I can put the ID of the 2nd list item into a variable and then delete that with the 2nd ajax function. Here is the code below...first ajax is working and 2nd ajax fails. Thanks for any help you can provide:

destroy: function (options) {
console.log(options);
var objId = options.data.Id;
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl +
"/_api/Web/Lists/GetByTitle('GalleryItems')/items(" + objId + ")",
dataType: "json",
cache: false,
data: {
models: kendo.stringify(options.data.models)
},
type: 'DELETE',
headers: {
"X-RequestDigest": $('#__REQUESTDIGEST').val(),
'Accept': 'application/json; odata=verbose',
"If-Match": "*"
},
contentType: "application/json",
success: function (result) {
options.success(result)
},
error: function(result) {
options.error(result)
}
})
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl +
"/_api/Web/Lists/GetByTitle('GalleryItemsPublished')/items(" + objId + ")",
dataType: "json",
cache: false,
data: {
models: kendo.stringify(options.data.models)
},
type: 'DELETE',
headers: {
"X-RequestDigest": $('#__REQUESTDIGEST').val(),
'Accept': 'application/json; odata=verbose',
"If-Match": "*"
},
contentType: "application/json",
success: function (result) {
options.success(result)
},
error: function(result) {
options.error(result)
}
});
}
Tsvetomir
Telerik team
commented on 05 May 2021, 12:40 PM

Hi Daniel. The information that is passed into the destroy function is for a single grid only. In order to obtain the item in the second grid, you should know which field can be used to match the items. Since the ID values are different, you should come up with a field upon which you can find the item in the other grid. Once you find the matching item, get its ID and perform the AJAX request.
0
Kyle
Top achievements
Rank 1
answered on 04 Jun 2012, 08:00 PM
Awesome, that did the trick! Thanks Jerry.
Tags
Grid
Asked by
Kyle
Top achievements
Rank 1
Answers by
Jerry T.
Top achievements
Rank 1
Kyle
Top achievements
Rank 1
Share this question
or