[ 6 posts ]

Mark Johnson

  • Username: MJohnson
  • Joined: Tue Mar 23, 2010 6:35 am
  • Posts: 9
  • Offline
  • Profile

How to change the "Data error." message when 0 results

Post Posted: Thu May 06, 2010 1:31 am
+0-
Hi I could really use some help.

When i am returning 0 results / empty array to my datasource - the datable shows a message of "Data error.", I feel this is rather unsightly but I cant for the life of me figure out a way to change this message to something more friendly.

Is it possible to have it display something else ?

edit : to be more specific:

at the doBeforeParseData ( oRequest , oFullResponse , oCallback ) function when i return no results the oFullResponse param is null - which is what i assume causes the "Data error." to display.

Ideally it would say "No results returned"

Can anyone help?

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: How to change the "Data error." message when 0 results

Post Posted: Thu May 06, 2010 1:59 am
+0-
instead of null, it should be [], an empty array, not no array. It does expect an array, even if empty

Mark Johnson

  • Username: MJohnson
  • Joined: Tue Mar 23, 2010 6:35 am
  • Posts: 9
  • Offline
  • Profile

Re: How to change the "Data error." message when 0 results

Post Posted: Thu May 06, 2010 2:33 am
+0-
Hi satyam thanks for your response, I have implemented your suggestion as shown below, however i still seem to be getting the "Data error." message?

Should i be parsing the empty array into JSON or something?

Code:
         messages_data_source = new YAHOO.util.XHRDataSource("CIIM/ValidationResults?" ,
         {   
            responseType : YAHOO.util.DataSource.TYPE_JSON,

            doBeforeParseData : function( oRequest , oFullResponse , oCallback )
            {
               if(!oFullResponse)
               {
                  oFullResponse = [];
               }
               return oFullResponse;
            },
            
            responseSchema :
            {
               resultsList :      "validation_results",
               fields :       [    {key : "id"},
                              {key : "conformance"},
                              {key : "status"},
                              {key : "messages"} ]
            }
});

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: How to change the "Data error." message when 0 results

Post Posted: Thu May 06, 2010 5:20 am
+0-
You still have to respect the structure of oFullResponse, you cannot just set oFullResponse to [] or null or whatever. oFullResponse has a place for the data, which you are configuring through the resultsList property. The oFullResponse you return should still have that.

The easiest way, instead of theorizing, is to put a breakpoint in doBeforeParseData and get a valid, non-empty reply (which I assume you are able to display normally) and check out where the data is, it should be an array of object literals. It is that array which you should replace with an empty array, leaving the rest just the same.

Mark Johnson

  • Username: MJohnson
  • Joined: Tue Mar 23, 2010 6:35 am
  • Posts: 9
  • Offline
  • Profile

Re: How to change the "Data error." message when 0 results

Post Posted: Thu May 06, 2010 5:24 am
+0-
Thankyou I will have a go at that now and see if I can put your suggestion into practise.

Mark Johnson

  • Username: MJohnson
  • Joined: Tue Mar 23, 2010 6:35 am
  • Posts: 9
  • Offline
  • Profile

Re: How to change the "Data error." message when 0 results

Post Posted: Thu May 06, 2010 5:46 am
+0-
THANKYOU SO MUCH!! it now works!

solution for JSON below:

Code:
messages_data_source = new YAHOO.util.XHRDataSource("CIIM/ValidationResults?" ,
         {   
            responseType : YAHOO.util.DataSource.TYPE_JSON,

            doBeforeParseData : function( oRequest , oFullResponse , oCallback )
            {
               if(!oFullResponse)
   {
         oFullResponse = {"results":[]};
   }               
              return oFullResponse;
            },
           
            responseSchema :
            {
               resultsList :      "results",
               fields :       [    {key : "id"},
                              {key : "conformance"},
                              {key : "status"},
                              {key : "messages"} ]
            }
});
  [ 6 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum