正文

应用Ext做个简单的表格2008-10-14 23:19:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lovebugs/38904.html

分享到:

          Ext是js界面编程的一个封装包,它包含了大部分的UI组件。今天就来应用Ext.grid.GridPanel组件创建个简单的表格。

 大致步骤分成以下几步:

1、创建表格数据源,可以是外部读入的数据,也可以是数组定义的。

var  myData=[
  ['Apple',29.89,0.24,0.81,'9/1 12:00am'],
  ['Ext',83.81,0.28,0.34,'9/12 12:00am'],
  ['Google',71.72,0.02,0.03,'10/1 12:00am'],
  ['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
  ['Yahoo!',29.01,0.42,1.47,'5/22 12:00am']
 ];  

再用Ext.data.ArrayReader创建列格式

 var myReader = new Ext.data.ArrayReader({}, [
  {name: 'company'},
  {name: 'price', type: 'float'},
  {name: 'change', type: 'float'},
  {name: 'pctChange', type: 'float'},
  {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
 ]);

2、创建表格体

var grid = new Ext.grid.GridPanel({
  store: new Ext.data.Store({
   data: myData,
   reader: myReader
  }),
  columns: [     //是把列格式与列形成映射
   {header: "Company", width: 120, sortable: true, dataIndex: 'company'},
   {header: "Price", width: 90, sortable: true, dataIndex: 'price'},
   {header: "Change", width: 90, sortable: true, dataIndex: 'change'},
   {header: "% Change", width: 90, sortable: true, dataIndex: 'pctChange'},
   {header: "Last Updated", width: 120, sortable: true,
    renderer: Ext.util.Format.dateRenderer('m/d/Y'),
                         dataIndex: 'lastChange'}
  ],
  viewConfig: {
   forceFit: true
  },
  renderTo: 'content',
  title: 'My First Grid',
  width: 500,
  height:500,
  frame: true
 });

3、在html文件中加入

<div id='content'></div>.当然要用Ext.onReady()装载代码。

 

 

阅读(2582) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册