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

Quicker way to declare datasource using WebAPI

7 Answers 691 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
improwise
Top achievements
Rank 1
Iron
Iron
improwise asked on 14 Dec 2015, 04:13 PM

If you have a WebAPI setup to identify which method(s) to use based on the HTTP Request type (Get, Post etc.), is there a quicker/shorter way to define a Kendo UI DataSource than below that is a lot of repetetive/identical code? Perhaps something that we just have to tell about the base URL and datatype, and then it will by itself figure out that a "read:" should use GET, "create:" should use POST etc. 

 

       dataSource: {

            transport: {

                read: {
                    url: "/api/AccommodationTypeViewModels",
                    
                    datatype: "json",
                    type: "GET"
                },
create: { 
   url: "/api/AccommodationTypeViewModels",
   datatype: "json",
   type: "POST"
},
update:
                  {
                      url: function (data) {
                          return "/api/AccommodationTypeViewModels/" + data.Id;
                      },
                      datatype: "json",
                      type: "PUT"
                  },
destroy: { 
   url: function (data) {
       return "/api/AccommodationTypeViewModels/" + data.Id;
   },
   datatype: "json",
   type: "DELETE"
}
},

 

 

7 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 16 Dec 2015, 08:51 AM

Hello Patrik Johansson,

 

I would suggest to review the following samples that might meet your requirements: 

 

   - grid-webapi-crud/ - This is a sample web site which shows how to use ASP.NET WebAPI CRUD with Kendo UI Grid. It uses the Kendo.DynamicLinq NuGet package.

 

   - Use WebAPI with Server-Side Operations example shows how to implement server-side operations using UI for ASP.NET MVC  and ToDataSourceResult extension method. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 16 Dec 2015, 12:05 PM
The first example just show a similar solution to the one in my post (at least in the Default.aspx page) and the second link is dead. 
0
Boyan Dimitrov
Telerik team
answered on 17 Dec 2015, 11:27 AM

Hello,

 

I would like to apologize for the broken link. 

The following Use WebAPI with Server-Side Operations link should work fine. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 20 Dec 2015, 03:39 PM
[quote]Boyan Dimitrov said:

Hello,

 

I would like to apologize for the broken link. 

The following Use WebAPI with Server-Side Operations link should work fine. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 

[/quote]

 

The link works but I can't see how it relates to my question? 

0
Boyan Dimitrov
Telerik team
answered on 22 Dec 2015, 06:38 PM

Hello Patrik Johansson,

 

Actually this example shows how to use the spacial type of the Kendo UI DataSource "webapi":

 

$("#grid").kendoGrid({
        columns: [
              //removed for brevity
        ],
        ...
        dataSource: {
            type: "webapi"
         ...

 

It requires to include a reference to the Kendo.Mvc.UI and Kendo.Mvc.Extensions assemblies (on the server) in order to use the WebApiDataSourceRequestModelBinder as shown in the api controller. This helps to populate the DataSourceRequest request object with information about sorting, filtering and etc. 

This object will have all the information you need in order to get the desired portion of the data using the ToDataSourceResult extension method. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 19 Jan 2016, 07:56 AM

Hi,

can this also handle odata-v4 with webapi?

0
Boyan Dimitrov
Telerik team
answered on 21 Jan 2016, 07:46 AM

Hello Benjamin,

 

The Odata 4 with WebAPI controller project shows how to configure the dataSource to communicate with the WebAPI controller through the Odata 4 protocol. Please note that Odata v4 is not fully supported. For more details please refer to the read me file. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
improwise
Top achievements
Rank 1
Iron
Iron
Answers by
Boyan Dimitrov
Telerik team
improwise
Top achievements
Rank 1
Iron
Iron
Simon
Top achievements
Rank 1
Share this question
or