This is a migrated thread and some comments may be shown as answers.

Configure Grid datasource to call Javascript function

1 Answer 446 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 30 Dec 2015, 10:51 PM

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.

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 04 Jan 2016, 12:47 PM

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
Tags
Grid
Asked by
Patrick
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or