EasyUI Forum
November 04, 2025, 04:33:37 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] datagrid: show data load error  (Read 22216 times)
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« on: April 25, 2016, 01:37:10 AM »

My remote server always returns a json object which is displayed as expected in edatagrid / datagrid. For e.g:
{"total":[1], "rows":[{ "id":1, "type":"Dummy Rack", "size":"40x50x60"}]}

In case of an error while handling request, the server may also send a json containing error text, for instance:
{"success":false,"message":"Received invalid Id:-1!"}

On client side however, this results in a background Javascript error: TypeError: rows is undefined

How should the json be formed so that in case of an error the "onLoadError" event of datagrid gets fired and the user be informed of error in an alert box?
« Last Edit: April 27, 2016, 09:54:21 AM by gordis gmbh » Logged
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« Reply #1 on: April 26, 2016, 04:09:11 AM »

Further experiments with this issue brings me to the conclusion that datagrid cannot handle incompatible json data!

Here is a demo, that results in a javascript error (in console) when you click on the button "get more data from server": http://jsfiddle.net/8g89fntz/3/

If the received json is not as expected, this should be handled and informed ...
I see no way to handle this because there isn't anything between onBeforeLoad and onLoadSuccess. And onLoadError doesn't get fired in this case!

Thanks in advance for having a look.
« Last Edit: April 26, 2016, 04:41:27 AM by gordis gmbh » Logged
Max Lamda
Newbie
*
Posts: 48


View Profile
« Reply #2 on: April 26, 2016, 04:33:15 AM »

onLoadError

fires, when you just return an empty page.

Logged
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« Reply #3 on: April 26, 2016, 04:42:59 AM »

@Max Lamda: yes, onLoadError does get fired in some cases... but not in this case (I have corrected this in my previous reply).
Logged
Max Lamda
Newbie
*
Posts: 48


View Profile
« Reply #4 on: April 26, 2016, 07:02:15 AM »

Look here

http://www.jeasyui.com/forum/index.php?topic=1410.0
Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #5 on: April 26, 2016, 03:53:40 PM »

The 'loader' function can be overridden to display the customized error message.
Code:
$('#dg').datagrid({
loader: function(param, success, error){
var opts = $(this).datagrid('options');
if (!opts.url) return false;
$.ajax({
type: opts.method,
url: opts.url,
data: param,
dataType: 'json',
success: function(data){
if (data.isError){
error(data);
} else {
success(data);
}
},
error: function(){
error.apply(this, arguments);
}
});
}

})

Please look at this update example http://jsfiddle.net/8g89fntz/5/
Logged
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« Reply #6 on: April 27, 2016, 09:53:45 AM »

Thanks for the support, that helped solve the problem!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!