Pass DataSourceRequest as Parameter in Javascript Ajax Call

3 posts, 0 answers
  1. Jillian
    Jillian avatar
    16 posts
    Member since:
    Aug 2011

    Posted 06 May 2014 Link to this post

    I have a page that has a grid and some filter fields (external from the grid).  The filtering gets applied to the grid in the JavaScript - which works fine.  I also have an export button that I need to export the data in my grid - since my grid does not contain all the data that my export needs, my thought was to pass the DataSourceRequest as a parameter to my Ajax call, select my data and then use the "toDataSourceResult()" as happens in my ajax read controller action. This is not working. 

    I have the following code in my javascript function that builds my datasource request, and passes it in as a parameter, but my DataSourceRequest object in my controller action contains null values for filter, sort, etc.

    var grid = ${"#Persons").data("kendoGrid");
    var parameterMap = grid.dataSource.transport.parameterMap;
    var requestObject = parameterMap({ Sorts: grid.dataSource.sort(), Filters: grid.dataSource.filter(), Groups: grid.dataSource.group()});

    How can I pass the datasource request as a parameter to my Ajax Controller action? I have attached a working sample project.

  2. Jillian
    Jillian avatar
    16 posts
    Member since:
    Aug 2011

    Posted 07 May 2014 in reply to Jillian Link to this post

    I resolved this by changing

    var requestObject = parameterMap({ Sorts: grid.dataSource.sort(), Filters: grid.dataSource.filter(), Groups: grid.dataSource.group()});

    to

    var requestObject = parameterMap({ sort: grid.dataSource.sort(), filter: grid.dataSource.filter(), group: grid.dataSource.group()});

    and adding my additional parameters I wanted to pass into the ajax controller action to my requestObject, instead of including them in the "data" setting of my javscript ajax call.
  3. EdsonF
    EdsonF avatar
    4 posts
    Member since:
    Nov 2012

    Posted 27 Aug 2014 in reply to Jillian Link to this post

    Hi Jillian

    I'm have exactly the same problem as you and although I change you sample project to what you mentioned on the second post, it still does not work - see attached.

    Can you help me find out what I'm doing wrong ?

    Thanks in advance

    Edson
Back to Top