3
votes

I am attempting to create a click event for an button that is not part of the Kendo UI Grid controls.

This was fairly easily accomplished with this code: https://stackoverflow.com/a/20973015/60629

Working DataSourceRequest Code:

JavaScript

$("#excel").kendoButton({
  click: function (event) {
    var grid = $('#grid_patients').data('kendoGrid');
        var parameterMap = grid.dataSource.transport.parameterMap;
        var sortData = grid.dataSource.sort();
        var filterData = grid.dataSource.filter();
        var groupData = grid.dataSource.group();
        var prepared = parameterMap({ sort: sortData, filter: filterData, group: groupData });

    $.post("/Root/Getresults", prepared, 
       function (data, status, xhr) {
         console.log("Ok!");
       }
    );
  }
});

Controller Code

public ActionResult Getresults([DataSourceRequest]DataSourceRequest request)
{
    ...

Additional Data

However, I need to also pass additional parameters. JavaScript Changes

 var extraParams = { /* appended data object */
     request: prepared,
     additionaldata: "test"
 };
 $.post("/Root/Getresults", extraParams, 
  ...

Controller

public ActionResult Getresults([DataSourceRequest]DataSourceRequest request, string additionaldata)
{
    ...

The original returns the DataSourceRequest with data and the secondary one will return the additionaldata, but has an empty request object.

I'm unsure how to proceed from here.

1
How did you bind grid_patients at initial page load?Win
It's an .NET MVC loading. I've actually figured this problem out now.. and feeling slightly moronic because of how long it took me. I didn't figure it out alone either.. a coworker with more Kendo under his belt did!JGood

1 Answers

3
votes

Thanks to a coworker the answer became fairly obvious! The mistake was in how I setup the JSON object being sent, the request parameter shouldn't be used.

var extraParams = { /* appended data object */
     sort: prepared.sort,
     filter: prepared.filter,
     group: prepared.group,
     additionaldata: "test"
 };

DataSourceRequest properties are automatically synced up to the parameter in the controller.