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

Grid throws undefined exception when the server responded with no-content

4 Answers 404 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Kasun
Top achievements
Rank 1
Kasun asked on 06 Mar 2018, 02:26 PM

I have a grid that is attached to a datasource. When it reads data, the server responses with no-content (when there is no data in the database). 

So the returned data is undefined. But the datasource is still trying to read the total which gives an exception. 

This line throws the error in kendo.all.js file 

  total: function (data) {
                return data.length;
            },

 

I was under the impression that the dataSource ignores any further processing if it does not get any valid data form the server. 

 

4 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 08 Mar 2018, 08:17 AM
Hello Kasun,

It is recommended to pass the same structure in the response, but with empty array for the data if there are no recors. Nevertheless, you could include conditions for checking if "data" exists, before trying to get its length:
total: function (data) {
      if(data){
                return data.length;}
     else{
                return 0;
      }
},


Best Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Kasun
Top achievements
Rank 1
answered on 08 Mar 2018, 12:23 PM

Hi, 

The code that I posted is from "kendo.all.js" file. Its not something that I wrote.  

0
Konstantin Dikov
Telerik team
answered on 09 Mar 2018, 06:38 AM
Hello Kasun,

You can define your custom function for retrieving the total in the schema of the dataSource:
Nevertheless, I would once again recommend to return an empty array instead of null, which will be the correct way for resolving the problem.


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Kasun
Top achievements
Rank 1
answered on 09 Mar 2018, 12:17 PM

Hi Dikov, 

Thats what I ended up doing. I returned an empty array in the Schema. Parse method. 

 

Tags
Data Source
Asked by
Kasun
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Kasun
Top achievements
Rank 1
Share this question
or