howto use 'data' in transport -> read

5 posts, 0 answers
  1. Sander
    Sander avatar
    8 posts
    Member since:
    Jan 2012

    Posted 28 Mar 2012 Link to this post

    I'm having trouble using the option 'data' to send variables to the server with a get command when doing a read.

    Example of the code that doesn't work:
    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: '/OFB/GetMijnUrenOpAct',
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                type: "GET",
    	    data: {
    		sendVar1: var1,
    
    		sendVar2: var2
    	    }
            } });

    Instead I now use the following:
    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: '/OFB/GetMijnUrenOpAct?sendVar1=' + var1 + "&sendVar2=" + var2,
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                type: "GET",
    
            }
    });
    I also tried doing a POST instead of a GET.
    Is there another way to do this?

  2. Sander
    Sander avatar
    8 posts
    Member since:
    Jan 2012

    Posted 28 Mar 2012 Link to this post

    Fixed it by using the parameterMap.

    var dataSource = new kendo.data.DataSource({
    	transport: {
    		read: {
    			url: '/OFB/GetMijnUrenOpAct',
    			dataType: "json",
    			type: "POST",
    		},
    		create: {
    			url: '/OFB/PostMijnUrenOpAct',
    			dataType: "json",
    			type: "POST"
    		},
    		parameterMap: function (data, type) {
    			if(type = "read"){
    				var values = {};
    				values["type"] = typeId;
    				values["actId"] = itemId;
    				return values;
    			}
    			else if (type === "create") {
    				return JSON.stringify(data);
    			}
    		}
    	},
  3. Kendo UI is VS 2017 Ready
  4. Nick Wu
    Nick Wu avatar
    22 posts
    Member since:
    Aug 2005

    Posted 07 Apr 2012 Link to this post

    when use jQuery's ajax method like below, it will run "getCurrentCategoryId" method then generate url like "api/movie/getByCategory?id=thecurrentvalue" .
    $.ajax({
        url: "/api/Movie/getByCategory",
        data: { id: getCurrentCategoryId() },
        type: "GET"             
      });

    why must customize "id=thecurrentvalue" by myself again in "parameterMap"  when use kendo DataSource ? it's more different than jQuery default way. 

    Hope  the document about DataSource can afford more details, thanks.



  5. Jonathan
    Jonathan avatar
    10 posts
    Member since:
    Jun 2012

    Posted 18 Jul 2012 Link to this post

    @ Sander, Thank you.  This was immensely helpful.
    @ Kendo, The documentation for dataSource.transport.parameterMap does not specify that the property can be assigned to a function with these parameters.  Please update the documentation.
  6. tlaguz
    tlaguz avatar
    1 posts
    Member since:
    Jun 2015

    Posted 27 Oct in reply to Sander Link to this post

    if(type = "read"){

     

    seriously? 

Back to Top
Kendo UI is VS 2017 Ready