EasyUI Forum
May 07, 2024, 03:57:43 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: [probably a bug]datagrid won't clear after getting empty rows from response  (Read 12516 times)
unclerayray
Newbie
*
Posts: 3


View Profile Email
« on: November 09, 2013, 09:59:09 PM »

I'm using version 3.3 of easyui for a CMS. It's a SSH structured project.
I got a datagrid defined like this:
Code:
<table id="dg" class="easyui-datagrid"  pagination="true"  pageSize=20  
loadMsg="Loading!"
data-options="autoRowHeight:true,fit:true,rownumbers:true,remoteSort: true,singleSelect:true,url:'../struts/Application_queryApplications',toolbar:'#tb'">
<thead>
<tr>
<th data-options="field:'applyId',width:80,hidden:true">ID</th>
<th data-options="field:'email',width:80">email</th>
</tr>
</thead>
</table>
And there is a toolbar '#tb' to filter data with conditions.
anyway the filter function is wrote like this.
Code:
var con = $('#confirm').combobox('getValue');
var fol = $('#follow').combobox('getValue');
// alert(con + ' '+fol);
$('#dg').datagrid('load', {confirmed : con, follow : fol});

I got test data records in my db so there are always records showed in the datagrid when first loading. It all goes well, so that means I did get the datagrid well defined. However something very strange happened when I was testing the filter function,  the datagrid won't refresh to a empty one when I got empty json rows from response. It remains the same before filtering instead. the response goes like this:
Code:
{'success':true,'message':'','total':0,'rows':[]}

I did a test from server side, to change the json response to
Code:
{'success':true,'message':'','total':0,'rows':[]}
in the first loading. The datagrid did load as a empty one. But once it was loaded with data. I can never get it to empty with this function:
Code:
$('#dg').datagrid('load', {confirmed : con, follow : fol});


This
Code:
$('#dg').datagrid('loadData', {'success':true,'message':'','total':0,'rows':[]});
can always empty the datagrid, but that's not the solution I'm looking for. In this case, I need to load data from server side by query it from db.

So I'm thinking the 'load' function of datagrid didn't remove the old rows before setting new rows. If there is a removal, It certainly didn't work in the empty row case. I could have look in the source code to find out why, only I'm pretty new in JS and the source code wasn't that readable. I'm there is no commont at all and all the functions are named with number and all. So here I'm. Looking for help! Grin

Any suggestion will be appreciated.
« Last Edit: November 10, 2013, 12:13:20 AM by unclerayray » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: November 09, 2013, 10:50:27 PM »

Please refer to http://www.jeasyui.com/tutorial/datagrid/datagrid24.php. It works well.
Logged
unclerayray
Newbie
*
Posts: 3


View Profile Email
« Reply #2 on: November 10, 2013, 12:12:39 AM »

I know it works. And I certainly knows how to define a datagrid. The thing is I think there may be a bug here. When got empty rows from server, datagrid should be able to clear and show a empty one, not stay where it used to be, right?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: November 10, 2013, 12:56:54 AM »

For the previous example, please enter some query parameter values that fetch empty data, the datagrid will clean all the rows.

http://www.jeasyui.com/tutorial/datagrid/datagrid24_demo.html
Logged
unclerayray
Newbie
*
Posts: 3


View Profile Email
« Reply #4 on: November 28, 2013, 08:22:56 AM »

For the previous example, please enter some query parameter values that fetch empty data, the datagrid will clean all the rows.

http://www.jeasyui.com/tutorial/datagrid/datagrid24_demo.html

It took me so long to find out...
turns out I was returning a json string with the character [  '  ] not   [ " ] when total amount is 0.
instead of returning {"success":true,"message":"","total":0,"rows":[]}
it returns {'success':true,'message':'','total':0,'rows':[]}
and datagrid couldn't parse it.
It never throw any error though.
So I think easyui should throw any error or hint, to remind people that they've got a json string with the wrong format
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!