How to load data using datasource

4 posts, 0 answers
  1. Andrea
    Andrea avatar
    60 posts
    Member since:
    Oct 2012

    Posted 21 Dec 2016 Link to this post

    Hello, i would like to make list to fill its data from an URL, but I am not able to do that, i tried to follow documentation but I have only found example of loading local data.

    That is working, but i would like to use ajax datasource, http://dojo.telerik.com/@andrea/uvanE

    That is the json data that correspond to the execution of the MVC controller I have server side: http://dojo.telerik.com/@andrea/uvanE/2

    that is my try to use the remote data http://dojo.telerik.com/@andrea/uvanE/3

    the json data have been generated by the following server code, and i do not know if it is in the correct format that the list expect

    [Authorize]
            [HttpPost]
            public ActionResult GetShippers([DataSourceRequest] DataSourceRequest request)
            {
                
                return Json(new string[] { "A", "B", "C" }.ToDataSourceResult(request));
            }
  2. Andrea
    Andrea avatar
    60 posts
    Member since:
    Oct 2012

    Posted 22 Dec 2016 in reply to Andrea Link to this post

    Well, finally is working, but the problem it's in the parsing of the result created by your ToDataSourceResult extension method.

    http://dojo.telerik.com/@andrea/uvanE/3

    To let my server controller work i had to change the return value as follows:

    [Authorize]
    [HttpPost]
    public ActionResult GetShippers([DataSourceRequest] DataSourceRequest request)
    {
       return Json(new string[] { "A", "B", "C" }.ToDataSourceResult(request).Data);
    }

     

  3. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    165 posts

    Posted 23 Dec 2016 Link to this post

    Hi Andrea,

    You should add the schema configuration to the Kendo UI Data Source. This will allow it to parse correctly,
    i.e:

    schema: {
     data: "Data",
     total: "Total",
     errors: "Errors"
    },

    I have updated it using the original server response in the first post:
    ({"Data":["A","B","C"],"Total":3,"AggregateResults":null,"Errors":null})

    http://dojo.telerik.com/UQARE

    If you wish to bind directly to action methods, we have a project referenced at:

    http://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/Editing/grid-bound-to-asp-net-mvc-action-methods---crud-operations

    Finally, the Kendo UI schema API reference is available at:

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema

    Let me know if you need more assistance.

    Regards,
    Alex Hajigeorgieva
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  4. Andrea
    Andrea avatar
    60 posts
    Member since:
    Oct 2012

    Posted 23 Dec 2016 in reply to Alex Hajigeorgieva Link to this post

    Thank you, that will let me use the mvc controllers as I always did when i used the grid.

     

    Best regards

    Andrea

Back to Top