Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9031529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:45:16+00:00 2026-06-16T07:45:16+00:00

I am using the $expand to get related data which works fine but I

  • 0

I am using the $expand to get related data which works fine but I need to change the data that is sent back
to the server when the data is updated

Example if my Server Side Data Model contains two entities
Contact
ID: number
firstName: string
middleName: string
lastname: string
ContactType: ContactType n-1

ContactType
ID: nubmer
name: string
ContactCollection: ContactType 1-n

Here is my datasource code

function GetContactDS(){
        var MyModel = kendo.data.Model.define({
                                id: "ID",
                                fields: {
                                __KEY: { type: "string" },
                                __STAMP: { type: "number" },
                                ID: { editable: false, nullable: true },                                                               
                                firstName: { type: "string" },
                                middleName: { type: "string" },                                                        
                                lastName: { type: "string" }                               
                                },                             
                            });

            var crudServiceBaseUrl = "http://127.0.0.1:8081/cors/Contact";
            var  MyDataSource = new kendo.data.DataSource({
        transport: {
       read: function(options) {
               $.ajax( {
                url: crudServiceBaseUrl + '/?$expand=ContactType',
                dataType: "json",
                data: options.data,
                success: function(result) {
                    options.success(result);
                }
            });
        },

    update: function(options) {
            $.ajax( {
                url: crudServiceBaseUrl + "/?$method=update",
                type: "POST",
                dataType: "json",
                data: kendo.stringify(options.data.models),
                success: function(result) {
                    // notify the DataSource that the operation is complete

                    options.success(result);
                }
            });
        },
                                destroy: {
                                url: crudServiceBaseUrl + "/?$method=delete",
                                type: "GET"
                                },
                                create: {
                                url: crudServiceBaseUrl + "/?$method=update",
                                dataType: "json",
                                type: "POST"
                                },
                                          parameterMap: function(options, operation) {
                                    if (operation !== "read" && options.models) {
                                       return  JSON.stringify({"__ENTITIES": options.models});
                                    }
                                }
                                },
                                batch: true,
                                pageSize: 30,
                                schema: {
                                     model: MyModel,
                                    data: "__ENTITIES"                         
                                    }

            });

      return MyDataSource;
}

The read request returns this data

{"__entityModel":"Contact","__COUNT":1,"__SENT":1,"__FIRST":0,"__ENTITIES":[{"__KEY":"7","__STAMP":9,"ID":7,"firstName":"jay","middleName":"a","lastName":"blue","ContactType":{"__KEY":"2","__STAMP":4,"ID":2,"name":"Home","contactCollection":{"__deferred":{"uri":"/rest/ContactType(2)/contactCollection?$expand=contactCollection"}}}}]}

Here is the code calling read and binding to grid

var ContactDS = GetContactDS();

    $("#grid").kendoGrid({
        selectable: "row",
        filterable: true,
        pageable: true,
        sortable: true,
        change: function(){

                 datamodel = this.dataItem(this.select());
                 ID = datamodel.ID

        },
        dataSource: ContactDS,
        columns: [
            { field: "ID" },
            { field: "firstName" },
            { field: "middleName" },
            { field: "lastName" },
            {field: "ContactType.name"}

        ]
    });

Which works fine I am getting the expanded info for ContactType in my datasource and it binds to a grid fine.
Now I want to update the after it the selected data row is read into a form, reading the data into the form works fine.

The problem is sending the update back to the server which expects a slightly different format for the related entity ContactType
It only needs the changed value of “__Key” to update
Here is my update function:

$("#update").click(function () {
                  datamodel.set("firstName", $("#firstName").val());
                  datamodel.set("lastName", $("#lastName").val());
                  datamodel.set("middleName", $("#middleName").val());
               //   datamodel.set("ContactType.__KEY",3);



                  ContactDS.sync();

Here is the data that the server expects

{ "__ENTITIES": [{"__KEY":"7","__STAMP":14,"firstName":"jay","middleName":"a","lastName":"red","ContactType":{"__KEY":"2"}}]}

Here is what kendo.datasource is sending

[{"__KEY":"7","__STAMP":12,"ID":7,"firstName":"jay","middleName":"a","lastName":"blue","ContactType":{"__KEY":"3","__STAMP":2,"ID":3,"name":"Work","contactCollection":{"__deferred":{"uri":"/rest/ContactType(3)/contactCollection?$expand=contactCollection"}}}}]

So how do I either reformat the data or define my model or datasource options to make sure that the extra ContactType fields are removed just leaving the updated “_KEY:” as well as wrapping the whole request in { “_ENTITIES”:}

Thanks for any help!

Dan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:45:17+00:00Added an answer on June 16, 2026 at 7:45 am

    I think I found the answer from this post

    It explains a little more on using parameterMap. If you look at the kendoui docs on parameterMap it seems to indicate that this is only for managing parameters like
    pageIndex,size,orderBy ect. But from the above post it shows you how to delete a related entity or you can just delete or modify the fields of an entity or related entity

    Example I can delete just the ContactTypeID of the related entity ContactType

    parameterMap: function(options, operation) {

                                if (operation == "create") {
    
                                return  JSON.stringify({"__ENTITIES": options.models});
                                }
                                else if (operation == "update") {
                                    debugger;
                                delete options.models[0].ContactType.ID;
                                return  JSON.stringify({"__ENTITIES": options.models});
                                 }
                            }
    

    Still have some work to do but I think this will get me there

    Thanks Pechka for your help

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’ve two div boxes that I’m using as a expand-collapse with some javascript but
im using expanded listview in my project, i need to expand the listview only
I’m using NHibernate for data access, but accessing it through a façade layer. This
I am using RelayCommand to handle a button click, I need to get the
Im using the jscrollpane jquery plugin. My content are images that expand when you
I need to know, are there any risks using the realloc() function to get
I am trying to get the list from server through javascript using following var
I am rendering a Tree using Jason array that i get from a jsp
I'm using animatedcollapse to create a menu with divs that expand when clicked. It
Reference: http://twitter.github.com/bootstrap/components.html#thumbnails Ive been using the Twitter Bootstrap, but I can't get the thumbnails

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.