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

5 posts, 0 answers
  1. Kasun
    Kasun avatar
    22 posts
    Member since:
    Oct 2016

    Posted 06 Mar Link to this post

    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. 

     

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2217 posts

    Posted 08 Mar Link to this post

    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.
  3. Kasun
    Kasun avatar
    22 posts
    Member since:
    Oct 2016

    Posted 08 Mar in reply to Konstantin Dikov Link to this post

    Hi, 

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

  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2217 posts

    Posted 09 Mar Link to this post

    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.
  5. Kasun
    Kasun avatar
    22 posts
    Member since:
    Oct 2016

    Posted 09 Mar in reply to Konstantin Dikov Link to this post

    Hi Dikov, 

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

     

Back to Top