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

JSON response define root

4 Answers 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 09 Jun 2015, 11:31 AM

Hi

I am using a customized response for the grid which contains the default "data" JSON in a property, such as:

{
  "success": true,
  "result": {
    "data": [
      {
        "srtOrder": 60,
        "id": 1
      },
      {
        "srtOrder": 70,
        "id": 1
      },
      {
        "srtOrder": 30,
        "id": 5
      }
    ],
    "total": 96,
    "aggregateResults": null,
    "errors": null
  },
  "error": null,
  "unAuthorizedRequest": false
}

 

So the grid should use the data from the "result" property.

How can I define this using the MVC version of the grid?

My model which is attached to the grid matches the "data" property.

4 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 11 Jun 2015, 07:54 AM

Hello Thomas,

 

This can be achieve by using custom data source in MVC wrappers. Example configuration:

 

.DataSource(dataSource =>        
  dataSource.Custom()
   .Transport(tr => tr.Read("Customers_Read", "Grid"))
   .Type("aspnetmvc-ajax")
   .Schema(sc => sc.Data("result.data").Total("total"))
)

 

 

Regards,
Nikolay Rusev
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
0
Thomas
Top achievements
Rank 1
answered on 12 Jun 2015, 06:58 AM

Hi Nikolay

Thanks for clarifying the Custom attribute. I have now tried the following:

 

        @(Html.Kendo().Grid<DP.Application.Dto.MyModel>()
            .Name("grid")
                  .Columns(columns =>
                      
            {
                columns.Bound(p => p.Id);
              

                columns.Command(command => { command.Edit(); command.Destroy();}).Width(220);
            })            
            .Scrollable(s => s.Height("auto"))
  
                
           .DataSource(dataSource => dataSource 
                                
                       .Custom()
                                          
                       .Type("aspnetmvc-ajax")
                       .Schema(sc => sc.Data("result.data").Total("total")
                                                                      
                                   
                                    .Model(model =>
                                    {
                                        model.Id(p => p.Id);
                                        model.Field(p => p.Id).Editable(false);

                                    })
                                                                     
                               )
                             
                        .Transport(tr => tr.Read("x_KendoRead", "ControllerName"))
   
                    )
                
                 );

 

However the grid renders empty. When I inspect the request using Fiddler, I do see the data in the format defined in my first post. Is there something else that must be configured?

 

Best Regards

Thomas

0
Accepted
Nikolay Rusev
Telerik team
answered on 12 Jun 2015, 08:27 AM

Hello Thomas,

You might be missing the kendo.aspnetmvc.min.js script which is required for the aspnetmvc-ajax transport.

You can find an example attached to this post.

Regards,
Nikolay Rusev
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
0
Thomas
Top achievements
Rank 1
answered on 12 Jun 2015, 10:38 AM

Hi Nikolay

 Thanks for example, which let me in the right direction to find the issue. It seemed like my custom response was using camelCase notation, but my model did not. Changing it solved the problem.

Tags
Grid
Asked by
Thomas
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or