Kendo DataSource Read Data and Parametermap Examples

Written on November 7, 2019 by Caterina Lyng

To add parameters to a Kendo dataSource transport operation, use transport read data by itself or in combination with transport parameterMap if the data needs encoding.

Generally, the parameterMap function is meant to transform the request, not to add new parameters to it.

Result of the two examples (firstSource & secondSource) further down on this page:

Block video until cookie consent is given

Kendo read data & parameterMap examples

The screenshot shows what can be seen in the Chrome DevTools > Network tab.

firstSource

Simple example with a parameter "someParam" added in transport > read > data:

var firstSource = new kendo.data.DataSource({
	transport: {
		read: {
			url: myUrlRoot + "kendo-test.json",
			dataType: "json",
			data: {
				someParam: 'someVal'
			},
		},
	},
});

firstSource.read();

secondSource

Example with Kendo parameterMap. The parameter is still present in transport > read > data but it is stringified in the parameterMap.

var secondSource = new kendo.data.DataSource({
	transport: {
		read: {
			url: myUrlRoot + "kendo-test.json",
			dataType: "json",
			data: {
				someParam: 'someVal'
			},
		},
		parameterMap: function (data, type) {
				return kendo.stringify(data);
		}
	},

});

secondSource.read();

"type" in the parameterMap function supports the following values: "create", "read", "update", "destroy".

Powered by
TRIMIT Portal Software