Quicker way to declare datasource using WebAPI

8 posts, 0 answers
  1. Patrik Johansson
    Patrik Johansson avatar
    270 posts
    Member since:
    May 2010

    Posted 14 Dec 2015 Link to this post

    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"
    }
    },

     

     

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 16 Dec 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Patrik Johansson
    Patrik Johansson avatar
    270 posts
    Member since:
    May 2010

    Posted 16 Dec 2015 in reply to Boyan Dimitrov Link to this post

    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. 
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 17 Dec 2015 Link to this post

    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!
     
  6. Patrik Johansson
    Patrik Johansson avatar
    270 posts
    Member since:
    May 2010

    Posted 20 Dec 2015 in reply to Boyan Dimitrov Link to this post

    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!
     

     

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

  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 22 Dec 2015 Link to this post

    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!
     
  8. Benjamin
    Benjamin avatar
    21 posts
    Member since:
    Apr 2015

    Posted 19 Jan in reply to Boyan Dimitrov Link to this post

    Hi,

    can this also handle odata-v4 with webapi?

  9. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 21 Jan Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready