Specify parameters to 'destroy' method?

3 posts, 1 answers
  1. Kyle
    Kyle avatar
    45 posts
    Member since:
    Mar 2012

    Posted 04 Jun 2012 Link to this post

    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. Answer
    Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 04 Jun 2012 Link to this post

    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

  3. Kyle
    Kyle avatar
    45 posts
    Member since:
    Mar 2012

    Posted 04 Jun 2012 Link to this post

    Awesome, that did the trick! Thanks Jerry.
Back to Top