分类: Java
2009-09-01 17:49:16
///
Ext.onReady(function(){
var data=[ [1, 'EasyJWeb', 'EasyJF',''],
[2, 'jfox', 'huihoo',''],
[3, 'jdon', 'jdon',''],
[4, 'springside', 'springside',''] ];
var store=new Ext.data.SimpleStore({data:data,fields:["id","name","organization","homepage"]});
var grid = new Ext.grid.GridPanel({
renderTo:"hello",
title:"中国Java开源产品及团队",
height:150,
width:600,
columns:[{header:"项目名称",dataIndex:"name"},
{header:"开发团队",dataIndex:"organization"},
{header:"网址",dataIndex:"homepage"}],
store:store,
autoExpandColumn:2
});
});
这个地方法应该注意,在HTML页面中有id为hello的标签,如:
否则将会报错:dom为空或不是对象。这个问题让我整了好久。
执行上面的代码,可以得到一个简单的表格,如下图所示:
Ext.onReady(function(){
var data=[ [1, 'EasyJWeb', 'EasyJF',''],
[2, 'jfox', 'huihoo',''],
[3, 'jdon', 'jdon',''],
[4, 'springside', 'springside',''] ];
var store=new Ext.data.SimpleStore({data:data,fields:["id","name","organization","homepage"]});
var colM=new Ext.grid.ColumnModel([{header:"项目名称",dataIndex:"name",sortable:true},
{header:"开发团队",dataIndex:"organization",sortable:true},
{header:"网址",dataIndex:"homepage"}]);
var grid = new Ext.grid.GridPanel({
renderTo:"hello",
title:"中国Java开源产品及团队",
height:200,
width:600,
cm:colM,
store:store,
autoExpandColumn:2
});
});
(按项目名称排序)
(可排序的列表头后面小按钮可以弹出操作菜单)
(可以指定隐藏哪些列)
function showUrl(value)
{
return ""+value+"";
}
Ext.onReady(function(){
var data=[ [1, 'EasyJWeb', 'EasyJF',''],
[2, 'jfox', 'huihoo',''],
[3, 'jdon', 'jdon',''],
[4, 'springside', 'springside',''] ];
var store=new Ext.data.SimpleStore({data:data,fields:["id","name","organization","homepage"]});
var colM=new Ext.grid.ColumnModel([{header:"项目名称",dataIndex:"name",sortable:true},
{header:"开发团队",dataIndex:"organization",sortable:true},
{header:"网址",dataIndex:"homepage",renderer:showUrl}]);
var grid = new Ext.grid.GridPanel({
renderTo:"hello",
title:"中国Java开源产品及团队",
height:200,
width:600,
cm:colM,
store:store,
autoExpandColumn:2
});
});
var data=[{id:1,
name:'EasyJWeb',
organization:'EasyJF',
homepage:''},
{id:2,
name:'jfox',
organization:'huihoo',
homepage:''},
{id:3,
name:'jdon',
organization:'jdon',
homepage:''},
{id:4,
name:'springside',
organization: 'springside',
homepage:''}
];
var store=new Ext.data.JsonStore({data:data,fields:["id","name","organization","homepage"]});
var colM=new Ext.grid.ColumnModel([{header:"项目名称",dataIndex:"name",sortable:true},
{header:"开发团队",dataIndex:"organization",sortable:true},
{header:"网址",dataIndex:"homepage",renderer:showUrl}]);
var grid = new Ext.grid.GridPanel({
renderTo:"hello",
title:"中国Java开源产品及团队",
height:200,
width:600,
cm:colM,
store:store,
autoExpandColumn:2
});
|
1
EasyJWeb
EasyJF
|
2
jfox
huihoo
|
3
jdon
jdon
|
4
springside
springside
var store=new Ext.data.Store({
url:"dataXml.xml",
reader:new Ext.data.XmlReader({
record:"row"},
["id","name","organization","homepage"])
});
function showUrl(value)
{
return ""+value+"";
}
Ext.onReady(function(){
var store=new Ext.data.Store({
url:"dataXml.xml",
reader:new Ext.data.XmlReader({
record:"row"},
["id","name","organization","homepage"])
});
var colM=new Ext.grid.ColumnModel([{header:"项目名称",dataIndex:"name",sortable:true},
{header:"开发团队",dataIndex:"organization",sortable:true},
{header:"网址",dataIndex:"homepage",renderer:showUrl}]);
var grid = new Ext.grid.GridPanel({
renderTo:"hello",
title:"中国Java开源产品及团队",
height:200,
width:600,
cm:colM,
store:store,
autoExpandColumn:2
});
store.load();
});
最后要注意的是:解析XML是可以的,但是必须将项目部署在WEB服务器中,才能显示出解析出来的数据,如果只打的是静态页面,则只能看到页面表格框架,并不能得到数据。
这个不知道为什么必须部署在Web服务器中,不知道是不是必须,只是部署以后就正常读数据了。有高手知者,请留言说一下。TIA。
chinaunix网友2009-09-19 12:58:34
已经找到原因了: 可以看这里:http://blog.chinaunix.net/u/22371/showart_2043667.html 因为Sote组件接受一个参数url,如果设置url,则ExtJS会创建一个与服务器交互的Ext.data.HttpProxy对象,该对象通过指定的Connection或Ext.Ajax.request来向服务端发送请求,从而可以读取到服务器端的数据。