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

howto use 'data' in transport -> read

4 Answers 2117 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Sander
Top achievements
Rank 1
Sander asked on 28 Mar 2012, 07:11 AM
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?

4 Answers, 1 is accepted

Sort by
0
Sander
Top achievements
Rank 1
answered on 28 Mar 2012, 08:11 AM
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);
			}
		}
	},
0
Nick Wu
Top achievements
Rank 1
answered on 08 Apr 2012, 03:49 AM
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.



0
Jonathan
Top achievements
Rank 1
answered on 18 Jul 2012, 03:48 PM
@ 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.
0
tlaguz
Top achievements
Rank 1
answered on 27 Oct 2016, 11:52 AM
if(type = "read"){

 

seriously? 

Tags
Data Source
Asked by
Sander
Top achievements
Rank 1
Answers by
Sander
Top achievements
Rank 1
Nick Wu
Top achievements
Rank 1
Jonathan
Top achievements
Rank 1
tlaguz
Top achievements
Rank 1
Share this question
or