EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: wade.zhu on August 12, 2014, 02:20:10 AM



Title: [FIXED] how can i clear the rows of datagrid
Post by: wade.zhu on August 12, 2014, 02:20:10 AM
i have a datagrid and a search form, when submit search form, i want to clear the previous results first, then load new data from remote.
i didn't find 'clear', 'reset' or something else in the docs
i try to use loadData method to load empty data instead, like this:

Code:

$('#dtgResult').datagrid('loadData', []);// supposed to clear previous results
$('#dtgResult').datagrid('load', serialize($('#frmSearch'));// fetch new results from remote


i found loadData method will trigger loader to load data from remote if opt.url is not empty
it is not supposed to load remote data after loadData from local.

is that a bug?
or is there anyway to meet my requirement?


Title: Re: how can i clear the rows of datagrid
Post by: hjzhbb7758 on August 12, 2014, 02:55:59 AM
hei,gay。where‘re you from /?


Title: Re: how can i clear the rows of datagrid
Post by: aswzen on August 12, 2014, 03:16:28 AM
try run this script..

Code:
$('#your_table_id').datagrid('loadData', {"total":0,"rows":[]});


Title: Re: how can i clear the rows of datagrid
Post by: wade.zhu on August 12, 2014, 07:38:15 PM
i found a bug of datagrid when no data filled, see the code bellow
Code:
<table class="easyui-datagrid" title="Basic DataGrid" style="width:700px;height:250px"
data-options="pagination:true,pageSize:10">
<thead>
<tr>
<th data-options="field:'itemid',width:80">Item ID</th>
<th data-options="field:'productid',width:100">Product</th>
<th data-options="field:'listprice',width:80,align:'right'">List Price</th>
<th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
<th data-options="field:'attr1',width:250">Attribute</th>
<th data-options="field:'status',width:60,align:'center'">Status</th>
</tr>
</thead>
</table>
url property is undefined, the pager shows incorrectly,that is why loadData will trigger loader to load data
_5d7(_60f); at line 8668 executed and loader will be called when loadData [].

Code:
var _614=$(_60f).datagrid("getPager");
if(_614.length){
var _615=_614.pagination("options");
if(_615.total!=data.total){
_614.pagination("refresh",{total:data.total});
if(opts.pageNumber!=_615.pageNumber){
opts.pageNumber=_615.pageNumber;
_5d7(_60f);//line 8668
}
}
}


Title: Re: how can i clear the rows of datagrid
Post by: stworthy on August 12, 2014, 07:55:41 PM
By default the 'pageNumber' property is set to 1, you can set it to 0 if the 'url' property is not defined.
Code:
$('#dg').datagrid({
  pageNumber:0
});


Title: Re: how can i clear the rows of datagrid
Post by: wade.zhu on August 12, 2014, 08:21:27 PM
yeah, it works upon lastest jquery.easyui.patch.js.
pageNumber will be reset to 1 when load remote.
thanks.
Code:
$('#dtgResult').datagrid('options').pageNumber = 0; // reset pageNumber for bug-fixing loadData
$('#dtgResult').datagrid('loadData', []);// supposed to clear previous results
$('#dtgResult').datagrid('load', serialize($('#frmSearch'));// fetch new results from remote

i suggest adding 'clear' method or something like this in next version. :)


Title: Re: [FIXED] how can i clear the rows of datagrid
Post by: zhcnlei on September 03, 2014, 01:25:35 AM
this problem does exist

[page] parameter, second post is 0

after using the patch, [page] parameter is 1

however, rows.length == 0, it will still be post twice


Title: Re: [FIXED] how can i clear the rows of datagrid
Post by: stworthy on September 03, 2014, 02:06:53 AM
Please try to download the patch from http://www.jeasyui.com/download/downloads/jquery-easyui-1.4-patch.zip.