extjs editorgrid刷新问题

gary412 2009-08-17 10:14:44
link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
num=1;
var data=[
['','','','']
];
js=new Ext.data.JsonStore({
data:data,
fields:["cnum","cxing","cchang","ckuan"]
});
var colM=new Ext.grid.ColumnModel([{

header:"车号",
width:200,
dataIndex:"cnum",
editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlanlk:false}))},
{header:"车型",
width:120,
dataIndex:"cxing",
editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlanlk:false}))
},

{header:"车长",

dataIndex:"cchang",

width:120,

editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlanlk:false}))},

{header:"车宽",

dataIndex:"ckuan",

width:120,

editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlanlk:false}))}

])
record=Ext.data.Record.create([
{name:'cnum'}
,

{name:'cxing'}
,

{name:'cchang'}
,

{name:'ckuan'}

]);
var dgrid= new Ext.grid.EditorGridPanel({
autoEncode:true,
frame:true,
width:600,
height:300,
clicksToEdit:1,
tbar:[
{pressed:true,text:'添加',handler:function(){
var initValue = {cnum:'',cxing:'',cchang:'',ckuan:''};
var p = new record(
initValue
);
js.insert(num,p);
num=num+1;
p.dirty=true;
p.modified=initValue;
if(js.modified.indexOf(p)==-1){
js.modified.push(p);
}
}
},
{xtype:"tbseparator"},
{pressed:true,text:'删除',handler:function(){
//Ext.Msg.confirm('信息','确定要删除?',

if(num==1){Ext.MessageBox.show({title:'系统提示',msg:'已经没有可供删除的记录!'})}
else {js.remove(js.getAt(num-1));num=num-1;}
}
},
{pressed:true,text:'刷新',handler:function(){ Ext.getCmp('grid').getGrid.store=js;
}}

],
cm:colM,
store : js,
//width:300,
//heigth:200,
autoShow:true,
renderTo:'grid'
})
})

</script>
<div id="grid"></div>



我的想法是给grid的store赋初值,可测试结果不行,不知道什么原因,高手指点
...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gary412 2009-08-17
  • 打赏
  • 举报
回复
分太少了结贴,换号送200分
gary412 2009-08-17
  • 打赏
  • 举报
回复
ls什么意思没看懂
hookee 2009-08-17
  • 打赏
  • 举报
回复

<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"> </script>
<script type="text/javascript" src="extjs/ext-all.js"> </script>
<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
num=1;
var data=[
['1','2','3','4']
];
js=new Ext.data.Store({
proxy:new Ext.data.MemoryProxy(data),
reader:new Ext.data.ArrayReader({},["cnum","cxing","cchang","ckuan"])
});
js.load();
var colM=new Ext.grid.ColumnModel([{

header:"车号",
width:200,
dataIndex:"cnum",
editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlanlk:false}))},
{header:"车型",
width:120,
dataIndex:"cxing",
editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlanlk:false}))
},

{header:"车长",

dataIndex:"cchang",

width:120,

editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlanlk:false}))},

{header:"车宽",

dataIndex:"ckuan",

width:120,

editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlanlk:false}))}

])
record=Ext.data.Record.create([
{name:'cnum'}
,

{name:'cxing'}
,

{name:'cchang'}
,

{name:'ckuan'}

]);
var dgrid= new Ext.grid.EditorGridPanel({
autoEncode:true,
frame:true,
width:600,
height:300,
clicksToEdit:1,
tbar:[
{pressed:true,text:'添加',handler:function(){
var initValue = {cnum:'',cxing:'',cchang:'',ckuan:''};
var p = new record(
initValue
);
js.insert(num,p);
num=num+1;
p.dirty=true;
p.modified=initValue;
if(js.modified.indexOf(p)==-1){
js.modified.push(p);
}
}
},
{xtype:"tbseparator"},
{pressed:true,text:'删除',handler:function(){
//Ext.Msg.confirm('信息','确定要删除?',

if(num==1){Ext.MessageBox.show({title:'系统提示',msg:'已经没有可供删除的记录!'})}
else {js.remove(js.getAt(num-1));num=num-1;}
}
},
{pressed:true,text:'刷新',handler:function(){ Ext.getCmp('grid').getGrid.store=js;
}}

],
cm:colM,
store : js,
//width:300,
//heigth:200,
autoShow:true,
renderTo:'grid'
})
})

</script>
<div id="grid"> </div>

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧