Configure Grid datasource to call Javascript function

2 posts, 1 answers
  1. Patrick
    Patrick avatar
    4 posts
    Member since:
    Mar 2015

    Posted 30 Dec 2015 Link to this post

    Hi,

     We use a framework that wrap every ajax response. Instead to have this :

    AggregateResults: null
    Data: [{Name: "name1", Title: "M.",},…]
    Errors: null
    Total: 4

     the response from controller method are :

    error: null
    result: {data: [{name: "name1", tile: "M."},…], total: 4,…}
    success: true
    unAuthorizedRequest: false

     

    I would like to use a javascript function so that  can manipulate the ajax response and extract the data before passing it to the Grid.

    Is there a way to achieve that? Thank you.

  2. Answer
    Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 04 Jan Link to this post

    Hello Patrick,

    When using ASP.NET MVC wrapper, this can be achieve via setting Custom DataSource configuration. This will allow you to set a custom function for the schema.parse and return the appropriate portion of the response. For example:

    @(Html.Kendo().Grid<ViewModel>()
        .Name("grid")
        /*..*/     
        .DataSource(dataSource => dataSource
            .Custom()
            .Type("aspnetmvc-ajax")
            .Transport(transport =>
                transport.Read(read => read.Action("Read", "Grid"))
            )
            .Schema(schema => schema.Parse(@<text>
                function(response) {
                    return response.result;
                }
            </text>)
            .Data("Data")
            .Total("Total")
            )
        )
    )

    Regards,
    Rosen
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top