4

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.

2
  • How did you bind grid_patients at initial page load? Commented Nov 26, 2014 at 0:48
  • 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! Commented Nov 26, 2014 at 1:34

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.