使用Ext.util.TaskRunner类实现,Ext的API中有示例,grid页面自动刷新

 是这样的??我有个不段变化的数据源。。想grid显示的随数据源不段变化。可是为什么grid显示就是不变啊。。grid里面的store是不段变的,,真晕啊,,那位大大帮忙看看啊。。。
Java代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HFC2.aspx.cs" Inherits="pro_HFC2" %>  
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 
<html xmlns="http://www.w3.org/1999/xhtml" >  
<head runat="server">  
    <title>无标题页</title>  
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <link href="../js/ext-all.css" rel="stylesheet" type="text/css" />  
    <script src="../js/ext-base.js"></script>  
    <script src="../js/ext-all.js"></script>  
    <script type="text/javascript" src="../js/ext-lang-zh_CN.js"></script>  
    <script type="text/javascript" src="../js/Portal.js"></script>  
    <script type="text/javascript" src="../js/PortalColumn.js"></script>  
    <script type="text/javascript" src="../js/Portlet.js"></script>  
    <link href="../js/portal.css" rel="stylesheet" type="text/css" />  
    <script type="text/javascript">Ext.BLANK_IMAGE_URL = '../images/default/s.gif';</script>         
 
   
</head>  
<script>  
     Ext.onReady(function(){  
       
var task={run:function(){  
     Ext.Ajax.request({  
          url:'../pro/HFC2.aspx?cmd=grid',  
                     success:function(response){   
                    var data=Ext.decode(response.responseText);  
//因为有几个grid,所以打算1次取到所有数据,再分个要的grid  
                    var store = new Ext.data.SimpleStore({  
                        fields:  [  
                            {name: 'oid'},  
                            {name: 'value'}  
                        ]  
                    });  
 
 
                     var cm=new Ext.grid.ColumnModel([  
                             {header:'名称',dataIndex:"oid",width:152, align:'center'},  
                             {header:'参数',dataIndex:"value",width:150, align:'center'}  
                            ]);  
                        var grid = new Ext.grid.GridPanel({  
                            width:325,  
                            height:300,  
                           stripeRows: true,  
                           autoScroll:true,   
                           cm:cm,  
                          // renderTo:'grid',  
                           store:store  
                        });   
                       
                        if(document.getElementById("grid").innerHTML=="")  
                        {  
                            grid.render("grid");  
                        }  
                        //store.removeAll();  
                        //grid.render("grid");  
                        grid.store.loadData(data);//store里面的数据是变的。但为什么显示不变啊??  
 
??  
                          
                        //alert(store.getAt(1).get('value')  )  
                        //grid.store.reload();  
                      // grid.reconfigure(store,cm);  
                    },  
                    failure:function(){}          
     });  
 
     }, interval:3000};  
        var taskRunner=new Ext.util.TaskRunner();  
        taskRunner.start(task);  
var viewport = new Ext.Viewport({  
        border :false,  
       autoScroll:true,   
        region:'nori',  
        items:[  
        {  
            xtype:'portal',  
            margins:'5 0 5 0',  
            items:[{  
                columnWidth:.33,  
                style:'padding:3px 0 3px 3px',  
                items:[{  
                    title: 'aa',  
                    html: "<div id='main' style:'height:500px'>d</div>" 
                }]  
            },{  
                columnWidth:.33,  
                  
                style:'padding:3px 0 3px 3px',  
                items:[{  
                    title: '基本属性',  
//                    items:[grid]  
                     html:"<div id='grid'></div>" 
                }]  
            },{  
                columnWidth:.33,  
                style:'padding:3px 0 3px 3px',  
                items:[{  
                    title: '统计信息',  
                    html: "dadad" 
                },{  
                    title: 'Another Panel 3',  
                    html: "dadad" 
                }]  
                }  
             ]  
        },{title:'da',html:'ddaa',height:100}  
        ]  
    });  
       
       
     });     
</script>  
<body>  
    <div id="nori"></div>  
     
</body>  
</html> 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HFC2.aspx.cs" Inherits="pro_HFC2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="../js/ext-all.css" rel="stylesheet" type="text/css" />
    <script src="../js/ext-base.js"></script>
    <script src="../js/ext-all.js"></script>
    <script type="text/javascript" src="../js/ext-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/Portal.js"></script>
    <script type="text/javascript" src="../js/PortalColumn.js"></script>
    <script type="text/javascript" src="../js/Portlet.js"></script>
    <link href="../js/portal.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">Ext.BLANK_IMAGE_URL = '../images/default/s.gif';</script>      

 
</head>
<script>
     Ext.onReady(function(){
    
var task={run:function(){
     Ext.Ajax.request({
          url:'../pro/HFC2.aspx?cmd=grid',
                     success:function(response){
                    var data=Ext.decode(response.responseText);
//因为有几个grid,所以打算1次取到所有数据,再分个要的grid
                    var store = new Ext.data.SimpleStore({
                        fields:  [
                            {name: 'oid'},
                            {name: 'value'}
                        ]
                    });


                     var cm=new Ext.grid.ColumnModel([
                             {header:'名称',dataIndex:"oid",width:152, align:'center'},
                             {header:'参数',dataIndex:"value",width:150, align:'center'}
                            ]);
                        var grid = new Ext.grid.GridPanel({
                            width:325,
                            height:300,
                           stripeRows: true,
                           autoScroll:true,
                           cm:cm,
                          // renderTo:'grid',
                           store:store
                        });
                    
                        if(document.getElementById("grid").innerHTML=="")
                        {
                            grid.render("grid");
                        }
                        //store.removeAll();
                        //grid.render("grid");
                        grid.store.loadData(data);//store里面的数据是变的。但为什么显示不变啊??

??
                       
                        //alert(store.getAt(1).get('value')  )
                        //grid.store.reload();
                      // grid.reconfigure(store,cm);
                    },
                    failure:function(){}       
     });

     }, interval:3000};
        var taskRunner=new Ext.util.TaskRunner();
        taskRunner.start(task);
var viewport = new Ext.Viewport({
        border :false,
       autoScroll:true,
        region:'nori',
        items:[
        {
            xtype:'portal',
            margins:'5 0 5 0',
            items:[{
                columnWidth:.33,
                style:'padding:3px 0 3px 3px',
                items:[{
                    title: 'aa',
                    html: "<div id='main' style:'height:500px'>d</div>"
                }]
            },{
                columnWidth:.33,
               
                style:'padding:3px 0 3px 3px',
                items:[{
                    title: '基本属性',
//                    items:[grid]
                     html:"<div id='grid'></div>"
                }]
            },{
                columnWidth:.33,
                style:'padding:3px 0 3px 3px',
                items:[{
                    title: '统计信息',
                    html: "dadad"
                },{
                    title: 'Another Panel 3',
                    html: "dadad"
                }]
                }
             ]
        },{title:'da',html:'ddaa',height:100}
        ]
    });
    
    
     });  
</script>
<body>
    <div id="nori"></div>
  
</body>
</html>

问题补充:
我用grid.reconfigure(store, new Ext.grid.ColumnModel(cm));
怎么包错啊。包错信息:this.view is null

问题补充:
自己解决了
--------------------------------------------------------------------------------
该问题已经关闭: 自己解决了
问题答案可能在这里 → 寻找更多解答
Ext 实现 更新列标题和数据,同时满足分组等现实问题
请教大家如何将页面的布局做成图2的那样??
如何获取上级容器?[GridPanel->bbar(PagingToolbar)->Item中获取GridPanel?]
SOS EXT Grid 如和提交 大侠们
EXTJS传值问题

回答


其实很简单的,主要就是以下三项.
//重新绑定grid
this.grid.reconfigure(newStore, new Ext.grid.ColumnModel(cm1));
//重新绑定分页工具栏
this.pagingBar.bind(newStore);
//重新加载数据集
newStore.load({params:{start:0,limit:10}});

lovewhzlq (CTO) 2009-06-23
设置一个定时器进行轮询,每隔多少秒调用一次加载store的url,然后重新load
laitaogood (资深程序员) 2009-06-23
lovewhzlq 正解

 

 

 

 

 

 

Ext: 双击Gird中的一行,获取这行记录,然后实时刷新另外一个Grid
Grid, Ext, Gird, 实时, 获取
JScript code
groupInfoGrid.addListener('rowdblclick', groupInfoDetailed);
function groupInfoDetailed(){ 
groupInfoDetailedStore.removeAll(); 
var record = groupInfoGrid.getSelectionModel().getSelected();
var dname=record.data['dutyname'];
var alarmtask = {
run: function(){
alert(dname);
groupInfoDetailedStore.load({params:{gname: dname}});
},
interval: 5000
}
Ext.TaskMgr.start(alarmtask);
}
假如grid如下:
A     123
B     456
C     789
当我双击A,弹出A,然后每5秒刷新一次
当我双击B,然后B,A 或者A,B然后每5秒刷新一次
这就不对了分析原因应该是执行了2个Task
这个该如何解决,始终让它执行双击的grid?

收藏 分享 00 0 我顶 我踩 
 
 
 
 

发短消息
加为好友
shla08801 当前离线

UID1007749 帖子114 精华0 积分562 阅读权限10 在线时间18 小时 注册时间2007-11-14 最后登录2010-7-10 
新手


 2#
 shla08801发表于 2010-3-18 15:29 | 只看该作者
因为你的groupInfoDetailedStore是个全局变量,所以groupInfoDetailedStore.load会刷新两个grid,
如果想要只执行一个task,
可以在执行前先停止其它的task
JScript code
var alarmtask = {
run: function(){
alert(dname);
groupInfoDetailedStore.load({params:{gname: dname}});
},
interval: 5000
}
[color=#FF0000]Ext.TaskMgr.stopAll();[/color]
Ext.TaskMgr.start(alarmtask);
 
 
 TOP
 
 

发短消息
加为好友
shaozr 当前离线

UID1007708 帖子104 精华0 积分559 阅读权限10 在线时间16 小时 注册时间2007-11-10 最后登录2010-7-9 
新手


 3#
 shaozr发表于 2010-3-19 17:38 | 只看该作者
还有个问题请教,如何判断一个task是否start?
HTML code
var task = {
run: function(){
Ext.fly('clock').update(new Date().format('g:i:s A'));
},
interval: 1000 //1秒
}
var runner = new Ext.util.TaskRunner();
runner.start(task);
如何知道这个task是否启动?
 
 
 TOP
 
 

发短消息
加为好友
wangshengren 当前离线

UID1002166 帖子120 精华0 积分610 阅读权限10 在线时间18 小时 注册时间2006-2-6 最后登录2010-7-10 
新手


 4#
 wangshengren发表于 2010-3-21 05:31 | 只看该作者
你點擊了A A程序就在執行了
在點擊B B程序開始執行  A這個時候也在執行 
你可以用一個變量在記錄task的狀態
 
 
 TOP
 
 

发短消息
加为好友
梁恩硕 当前离线

UID1009038 帖子104 精华0 积分517 阅读权限10 在线时间16 小时 注册时间2008-4-12 最后登录2010-7-8 
新手


 5#
 梁恩硕发表于 2010-3-22 12:13 | 只看该作者
怎么貌似看不懂哦。。。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值