Persist additional dataSource.read parameters on paganation in Kendo data grid

Jeremyx picture Jeremyx · Jun 9, 2015 · Viewed 8.3k times · Source

I have a Kendo Grid that loads data via ajax with a call to server-side ASP.NET read method:

 public virtual JsonResult Read(DataSourceRequest request, string anotherParam)

In my client-side JS, I trigger a read when a button is clicked:

grid.dataSource.read( { anotherParam: 'foo' });
grid.refresh();

This works as expected, only I lose the additional param when I move through the pages of results in the grid, or use the refresh icon on the grid to reload the data.

How do I persist the additional parameter data in the grid?

I have tried setting

grid.dataSource.data

directly, but without much luck. I either get an error if I pass an object, or no effect if I pass the name of a JS function that returns data.

Answer

Abbas Galiyakotwala picture Abbas Galiyakotwala · Jun 9, 2015

if you want to pass additional parameters to Read ajax datasource method (server side), you may use

.DataSource(dataSource => dataSource
            ...
            .Read(read => read.Action("Read", controllerName, new { anotherParam= "foo"}))
            ...
        )

if you want to pass additional parameters through client scripting you may use datasource.transport.parameterMap, something as below

parameterMap: function(data, type) {
  if (type == "read") {

     return { request:kendo.stringify(data), anotherParam:"foo" }
  }