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

DataSource still empy empty

4 Answers 1274 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
laurent
Top achievements
Rank 1
laurent asked on 25 Jun 2019, 01:25 PM

Hello,

After a countless of attempts and adjustements, it is still impossible to retrieve data from a datasource (to load a grid).

I use an API Net.Core that returns JSON (with Odata nugets).

Everything is OK : json is return, callback is triggered (I check with Fiddler 4 of Telerik).

HTML side : I use Odata type for the Transport (I noticed it is impossible to get a callback from my API if I use "webapi" or anything else for instance).

HTML file (body):

<div id="example">
            <div id="grid"></div>
            <script>
   
   $(document).ready(function () {
   
   var dSource = new kendo.data.DataSource({
      type: "odata",
      dataType: "json",
      serverPaging: true,
                        serverSorting: true,
                        pageSize: 12,
      
      transport: {
        read: "https://localhost:44363/api/students"
          
         }
     });
   // read data from the remote service
            dSource.read();
   var data = dSource.data();
   alert(data[0]);
   
   });
           
            </script>
        </div>

 

 

4 Answers, 1 is accepted

Sort by
0
Accepted
Alex Hajigeorgieva
Telerik team
answered on 27 Jun 2019, 10:02 AM
Hello, Laurent,

Thank you very much for the provided snippet and the screenshot. I am sorry to hear that you have spent so much time on this.

The main reason it seems like it does not work is that the read() operation is not yet complete at the time when the code tries to get the first data item. Since the data is not yet processed and part of the internal data array,, the data() method returns undefined.

This is why the read() method is designed to return a promise - so that you can be certain the data is received:

https://dojo.telerik.com/@bubblemaster/AHiCufuL

// read data from the remote service and then check it
 dSource.read().then(function(){
   var data = dSource.data();
   kendo.alert(kendo.stringify(data[0]));
 });

Additionally, the dataType will not take effect at root level, it only exists as part of the transport CRUD operations (this should not make a difference but I wanted to share it with you nonetheless):

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource



Finally to load a grid, you do not need to call the read action yourself, the grid widget will ask for its data by default. Here is our odata data with a grid for your reference:

https://demos.telerik.com/kendo-ui/grid/remote-data-binding

Let me know how you get on.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
laurent
Top achievements
Rank 1
answered on 30 Jun 2019, 07:20 AM

Hello Alex,

Thanks a bunch for your answer.

But still nothing displayed !!!

I simply changed URL string in your code example: yours works perfectly and mine ...still shows nothing !

Anything else to suggest ?

NB: if I connect datasource with a controller output within a dot.net Core solution : no problem, data are displayed.:)

But you do know of course, we cannot settle for that way because the great benefit of "Kendo JQuery" is that the client must be completely out of the service whatever it can be! (Java, ERP, Azur etc ...- services)

Kinds Regards.

0
laurent
Top achievements
Rank 1
answered on 30 Jun 2019, 08:08 AM

Euh Alex , just a little question : is there any config files to set in order to use Telerik components ?

We can assume that anyone (whoever and wherever) can use (in free way) Telerik services by coding a HTML page like this one by  reaching any endpoint services ?

NB : I' ve got the trial version and Liebherr (I work on behalf of this company) is going to buy a commercial version (purchase order is launched) 

0
Alex Hajigeorgieva
Telerik team
answered on 02 Jul 2019, 03:30 PM
Hello, Laurent,

I would be happy to assist you in querying the service that you have. Could you share the endpoint here? If it is confidential, then we can discuss it privately in a support thread.

Are you able to get the data from the endpoint in a simple $.ajax() request? In regards to reading data, the data source makes ajax requests and processes the parameters differently dependent on its type. The "odata" type produces this request:



Finally, I am very pleased to welcome you to the Kendo UI Developers' community! The license agreement for Kendo UI is available here.

Look forward to hearing back from you.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Data Source
Asked by
laurent
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
laurent
Top achievements
Rank 1
Share this question
or