PDA

View Full Version : [4.1 B1]Bug in guaranteeRange



Dengqiao Huang
14 Jan 2012, 2:22 AM
Code:


start = Math.min(Math.max(start - me.numFromEdge - ((me.leadingBufferZone - me.trailingBufferZone) / 2), 0), me.totalCount - me.pageSize);
end = start + (me.pageSize - 1);

startPage = me.getPageFromRecordIndex(start);
endPage = me.getPageFromRecordIndex(end);


Calculated from the new "start" and "end", leading to "startPage" and "endPage" error, can not load data. After I block out ,It's OK.

Case:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../../Ext4/resources/css/ext-all.css"/>
<script type="text/javascript" src="../../Ext4/bootstrap.js"></script>
<script type="text/javascript" src="../../Ext4/locale/Ext-lang-zh_CN.js"></script>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">

Ext.define('Orders', {
extend: 'Ext.data.Model',
fields: [
{name:'OrderID',type:"int"},
'CustomerID','CustomerName',
{name:'OrderDate',type:"date",format:"Y-m-d"}
],
idProperty:"OrderID"
});


Ext.onReady(function(){
if(Ext.BLANK_IMAGE_URL.substr(0,4)!="data"){
Ext.BLANK_IMAGE_URL="./images/s.gif";
}

var store=Ext.create("Ext.data.Store",{
model:'Orders',
pageSize:100,
remoteFilter:true,
remoteSort:true,
buffered:true,
proxy: {
type: 'ajax',
api:{
read:'Orders.ashx'
//read:"/Chapter10/Orders" //java
},
reader:{
type: 'json',
root:"data"
}
},
storeId:"OrdersStore",
listeners:{
datachanged:function(store){
if(store.MyFilter){
var grid=Ext.getCmp("myGrid");
store.MyFilter=false;
grid.invalidateScroller();
}
}
}
})

Ext.create("Ext.grid.Panel",{
id:"myGrid",
renderTo:Ext.getBody(),
title:"Order List",
height:500,
width:800,
renderTo:Ext.getBody(),
store:"OrdersStore",
scroll:"both",
invalidateScrollerOnRefresh: false,
disableSelection:true,
tbar:[
"Range:",
{xtype:"datefield",width:120,id:"StartDate",format:"Y-m-d",value:new Date()},
"-",
{xtype:"datefield",width:120,id:"EndDate",format:"Y-m-d",value:new Date()},
{text:"Go",handler:function(){
var grid=this.up("gridpanel"),
stroe=grid.store,
start=Ext.getCmp("StartDate").getValue(),
end=Ext.getCmp("EndDate").getValue(),
params=store.getProxy().extraParams;
if(start>end){
Ext.Msg.alert("提示信息","开始日期不能大于结束日期!");
return;
}else if(start.getTime()==end.getTime()){
params.op="=";
}else{
params.op="between";
params.EndDate=Ext.Date.format(end,"Y-m-d");
}
params.StartDate=Ext.Date.format(start,"Y-m-d");
store.prefetchData.clear();
store.MyFilter=true;
if(store.currentPage==1){
store.load();
}else{
store.guaranteeRange(0,99);
}
}},
{text:"Show All",handler:function(){
var grid=this.up("gridpanel");
stroe=grid.store,
params=store.getProxy().extraParams;
params.op="";
params.EndDate="";
params.StartDate="";
grid.store.prefetchData.clear();
grid.store.MyFilter=true;
if(store.currentPage==1){
store.load();
}else{
store.guaranteeRange(0,99);
}
}}
],
columns:[
{xtype:"rownumberer",sortable:false,width:60},
{text:'ID',dataIndex:'OrderID'},
{text:'Customer ID',dataIndex:'CustomerID'},
{text:'Customer',dataIndex:'CustomerName',sortable:false,flex:1},
{xtype:"datecolumn",text:'Order Date',dataIndex:'OrderDate',format:"Y-m-d",width:100}
]
});
store.guaranteeRange(0,99);
});
</script>
</body>
</html>

mitchellsimoens
15 Jan 2012, 2:30 PM
There is a bug reported that guaranteeRange needs to be improved.

hakana
6 Feb 2012, 8:08 AM
I'm not sure if this is the same issue. But when I call the guaranteeRange the
me.totalCount is undefined and start get undefined and that broke the function later.

start = Math.min(Math.max(start - me.numFromEdge - ((me.leadingBufferZone - me.trailingBufferZone) / 2), 0), me.totalCount - me.pageSize)