extjs学习笔记(三)最基本的grid
extjs的一个亮点就是提供了丰富的UI,使得没有艺术细胞的程序员也能做出绚丽的界面。把所有的UI集中到一起,有好处也有坏处,好处是有了统一的风格和接口,坏处是js文件过于庞大,使用extjs的最小集合也超过了500k,所以在有些项目中并不适用。jquery在这方面则正好相反,它的UI都以插件形式提供,可以需要什么就引用什么,所以非常小巧灵活,但由于插件往往是由不同的人或者团队来提供,界面和接口往往就不那么一致。反正是各有千秋吧。
今天学习extjs中的grid,它可以说是功能强大,无出其右,只有你想不到的,没有它做不到的,呵呵,好像是有点夸张了。好,不说废话了,我们就从最简单的grid开始,一步步来看看extjs给我们提供的grid究竟给我们提供了哪些功能。
一个grid包括一些行和列,在extjs里边,列由Ext.grid.ColumnModel来管理,我们来看看如何创建一个ColumnModel对象:
有了列,我们还需要一些数据来填充行,构造一个数组吧:
renderTo:指出grid构造出来之后要在哪里呈现,可以是一个元素的id,一个Dom结点或者一个Element对象,如果没有这个参数,就必须调用Ext.grid.GridPanel的render方法来呈现出grid。
stroe:可以简写为ds,以一个统一的接口提供数据给grid,,我们知道数据可能有很多种格式,除了我们用到的数组,还可以是json,xml等等,如果让grid负责来识别每一种数据格式显然不是一个好的设计思想,所以在extjs中有一个专门的类Ext.data.Store来负责数据的格式转换,这里我们用到它的子类ArrayStore,顾名思义,是专门针对数组来进行转换的。我们会专门有一个系列来讨论Ext.data命名空间下边的一些类,那时会对Store类进行深入的了解。现在我们只看看我们用到的fields字段,它是Ext.data.Field类的集合,该类有一个name属性,我们前边在ColumnModel里边置之不理的dataIndex就是引用了这个属性的值来对应列和Field之间的关系,type用来指出类型,默认是字符串类型,dateFormat则指出日期的格式。
cm:colModel的简写,这里放上我们前边构造好的ColumnModel对象就可以了。
stripeRows:是否显示条纹。
autoExpandColumn:自动扩充的列,该列会自动填充grid的空白空间。
height和width:grid的高度和宽度。
title:grid的标题。
现在我们运行一下看看效果,应该说这个grid还算漂亮,在列的名字上点击还能够进行排序,列的宽度可以自由拖动,位置也可以改变。按下ctrl键,我们可以选择多个行。当我们把鼠标移动到列名上,还可以看到出现一个倒立的小三角,点击出现个菜单,可以看到里边能对列进行排序,还可以隐藏列。不过我们也看到,日期的显示并不尽如人意,百分比依然是浮点数,而且我们通常用赤字表示亏损或者现在更为流行的说法负增长,如果在我们的grid里边,负增长也可以用赤字表现出来,效果应该会更好一些。extjs给我们提供了一个很方便的东西来实现我们的想法:renderer。在ColumnModel里边,我们可以给需要的列里边增加renderer来实现我们想要的效果。下边是改动后的ColumnModel:
现在运行程序,可以看到我们希望的效果了:负增长用了赤字来表示,作为对比,正的增长用了绿颜色,时间也按照我们希望的格式显示了出来。
有的时候,我们还希望给每一行编号,这个实现起来也很容易,我们只要在ColumnModel的构造函数里边加上new Ext.grid.RowNumberer()就可以了:
viewConfig:我们可以用这个参数来对grid的界面进行一些设置,详细内容可以查看帮助文档。
selModel:可以简写为sm,选择模型,比如是选择单元格还是选择整个行,默认是选择行。
今天学习extjs中的grid,它可以说是功能强大,无出其右,只有你想不到的,没有它做不到的,呵呵,好像是有点夸张了。好,不说废话了,我们就从最简单的grid开始,一步步来看看extjs给我们提供的grid究竟给我们提供了哪些功能。
一个grid包括一些行和列,在extjs里边,列由Ext.grid.ColumnModel来管理,我们来看看如何创建一个ColumnModel对象:
1var cm = new Ext.grid.ColumnModel([
2 {id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
3 {header: "Price", width: 75, sortable: true, dataIndex: 'price'},
4 {header: "Change", width: 75, sortable: true, dataIndex: 'change'},
5 {header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange'},
6 {header: "Last Updated", width: 85, sortable: true, dataIndex: 'lastChange'}
7]);
这里定义了五个列,列可以通过参数进行配置:id用来标识列,在css中使用该id可以对整列所有的单元格设置样式,可自动扩充的列也根据这个id来标识;header是列名字;width是列的宽度;sortable用来指明列是否可排序,dataIndex,先不管它。比较常用的参数还有renderer,指示列如何来呈现,后边会再详细介绍它。2 {id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
3 {header: "Price", width: 75, sortable: true, dataIndex: 'price'},
4 {header: "Change", width: 75, sortable: true, dataIndex: 'change'},
5 {header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange'},
6 {header: "Last Updated", width: 85, sortable: true, dataIndex: 'lastChange'}
7]);
有了列,我们还需要一些数据来填充行,构造一个数组吧:
1var myData = [
2 ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
3 ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
4 ['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'],
5 ['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
6 ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
7 ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am'],
8 ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
9 ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am'],
10 ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am'],
11 ['E.I. du Pont de Nemours and Company',40.48,0.51,1.28,'9/1 12:00am'],
12 ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am'],
13 ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am'],
14 ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am'],
15 ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
16 ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am'],
17 ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am'],
18 ['International Business Machines',81.41,0.44,0.54,'9/1 12:00am'],
19 ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am'],
20 ['JP Morgan & Chase & Co',45.73,0.07,0.15,'9/1 12:00am'],
21 ['McDonald\'s Corporation',36.76,0.86,2.40,'9/1 12:00am'],
22 ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am'],
23 ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am'],
24 ['Pfizer Inc',27.96,0.4,1.45,'9/1 12:00am'],
25 ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am'],
26 ['The Home Depot, Inc.',34.64,0.35,1.02,'9/1 12:00am'],
27 ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am'],
28 ['United Technologies Corporation',63.26,0.55,0.88,'9/1 12:00am'],
29 ['Verizon Communications',35.57,0.39,1.11,'9/1 12:00am'],
30 ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
31 ];
现在万事俱备只欠东风了,列定义好了,数据也有了,接下来就是把它们组装成一个grid。看一下完整的代码:2 ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
3 ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
4 ['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'],
5 ['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
6 ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
7 ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am'],
8 ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
9 ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am'],
10 ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am'],
11 ['E.I. du Pont de Nemours and Company',40.48,0.51,1.28,'9/1 12:00am'],
12 ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am'],
13 ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am'],
14 ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am'],
15 ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
16 ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am'],
17 ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am'],
18 ['International Business Machines',81.41,0.44,0.54,'9/1 12:00am'],
19 ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am'],
20 ['JP Morgan & Chase & Co',45.73,0.07,0.15,'9/1 12:00am'],
21 ['McDonald\'s Corporation',36.76,0.86,2.40,'9/1 12:00am'],
22 ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am'],
23 ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am'],
24 ['Pfizer Inc',27.96,0.4,1.45,'9/1 12:00am'],
25 ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am'],
26 ['The Home Depot, Inc.',34.64,0.35,1.02,'9/1 12:00am'],
27 ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am'],
28 ['United Technologies Corporation',63.26,0.55,0.88,'9/1 12:00am'],
29 ['Verizon Communications',35.57,0.39,1.11,'9/1 12:00am'],
30 ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
31 ];
1///<reference path="vswd-ext_2.0.2.js" />
2/*
3*作者:大笨
4*日期:2009-10-13
5*版本:1.0
6*博客地址:http://yage.cnblogs.com
7*/
8
9Ext.onReady(function() {
10 //构造列
11 var cm = new Ext.grid.ColumnModel([
12 { id: 'company', header: "Company", width: 160, sortable: true, dataIndex: 'company' },
13 { header: "Price", width: 75, sortable: true, dataIndex: 'price' },
14 { header: "Change", width: 75, sortable: true, dataIndex: 'change' },
15 { header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange' },
16 { header: "Last Updated", width: 85, sortable: true, dataIndex: 'lastChange' }
17 ]);
18 //构造数据
19 var myData = [
20 ['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],
21 ['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],
22 ['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am'],
23 ['American Express Company', 52.55, 0.01, 0.02, '9/1 12:00am'],
24 ['American International Group, Inc.', 64.13, 0.31, 0.49, '9/1 12:00am'],
25 ['AT&T Inc.', 31.61, -0.48, -1.54, '9/1 12:00am'],
26 ['Boeing Co.', 75.43, 0.53, 0.71, '9/1 12:00am'],
27 ['Caterpillar Inc.', 67.27, 0.92, 1.39, '9/1 12:00am'],
28 ['Citigroup, Inc.', 49.37, 0.02, 0.04, '9/1 12:00am'],
29 ['E.I. du Pont de Nemours and Company', 40.48, 0.51, 1.28, '9/1 12:00am'],
30 ['Exxon Mobil Corp', 68.1, -0.43, -0.64, '9/1 12:00am'],
31 ['General Electric Company', 34.14, -0.08, -0.23, '9/1 12:00am'],
32 ['General Motors Corporation', 30.27, 1.09, 3.74, '9/1 12:00am'],
33 ['Hewlett-Packard Co.', 36.53, -0.03, -0.08, '9/1 12:00am'],
34 ['Honeywell Intl Inc', 38.77, 0.05, 0.13, '9/1 12:00am'],
35 ['Intel Corporation', 19.88, 0.31, 1.58, '9/1 12:00am'],
36 ['International Business Machines', 81.41, 0.44, 0.54, '9/1 12:00am'],
37 ['Johnson & Johnson', 64.72, 0.06, 0.09, '9/1 12:00am'],
38 ['JP Morgan & Chase & Co', 45.73, 0.07, 0.15, '9/1 12:00am'],
39 ['McDonald\'s Corporation', 36.76, 0.86, 2.40, '9/1 12:00am'],
40 ['Merck & Co., Inc.', 40.96, 0.41, 1.01, '9/1 12:00am'],
41 ['Microsoft Corporation', 25.84, 0.14, 0.54, '9/1 12:00am'],
42 ['Pfizer Inc', 27.96, 0.4, 1.45, '9/1 12:00am'],
43 ['The Coca-Cola Company', 45.07, 0.26, 0.58, '9/1 12:00am'],
44 ['The Home Depot, Inc.', 34.64, 0.35, 1.02, '9/1 12:00am'],
45 ['The Procter & Gamble Company', 61.91, 0.01, 0.02, '9/1 12:00am'],
46 ['United Technologies Corporation', 63.26, 0.55, 0.88, '9/1 12:00am'],
47 ['Verizon Communications', 35.57, 0.39, 1.11, '9/1 12:00am'],
48 ['Wal-Mart Stores, Inc.', 45.45, 0.73, 1.63, '9/1 12:00am']
49 ];
50
51 //构造grid
52 var grid = new Ext.grid.GridPanel({
53 renderTo: "grid",
54 store: new Ext.data.ArrayStore({
55 fields: [
56 { name: 'company' },
57 { name: 'price', type: 'float' },
58 { name: 'change', type: 'float' },
59 { name: 'pctChange', type: 'float' },
60 { name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia' }
61 ],
62 data:myData
63 }),
64 cm: cm,
65 stripeRows: true,
66 autoExpandColumn: 'company',
67 height: 350,
68 width: 600,
69 title: 'Array Grid'
70 });
71})
在extjs中,Ext.grid.GridPanel表示一个grid,它需要一个json对象作为参数来进行配置,我们看看用到的配置:2/*
3*作者:大笨
4*日期:2009-10-13
5*版本:1.0
6*博客地址:http://yage.cnblogs.com
7*/
8
9Ext.onReady(function() {
10 //构造列
11 var cm = new Ext.grid.ColumnModel([
12 { id: 'company', header: "Company", width: 160, sortable: true, dataIndex: 'company' },
13 { header: "Price", width: 75, sortable: true, dataIndex: 'price' },
14 { header: "Change", width: 75, sortable: true, dataIndex: 'change' },
15 { header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange' },
16 { header: "Last Updated", width: 85, sortable: true, dataIndex: 'lastChange' }
17 ]);
18 //构造数据
19 var myData = [
20 ['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],
21 ['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],
22 ['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am'],
23 ['American Express Company', 52.55, 0.01, 0.02, '9/1 12:00am'],
24 ['American International Group, Inc.', 64.13, 0.31, 0.49, '9/1 12:00am'],
25 ['AT&T Inc.', 31.61, -0.48, -1.54, '9/1 12:00am'],
26 ['Boeing Co.', 75.43, 0.53, 0.71, '9/1 12:00am'],
27 ['Caterpillar Inc.', 67.27, 0.92, 1.39, '9/1 12:00am'],
28 ['Citigroup, Inc.', 49.37, 0.02, 0.04, '9/1 12:00am'],
29 ['E.I. du Pont de Nemours and Company', 40.48, 0.51, 1.28, '9/1 12:00am'],
30 ['Exxon Mobil Corp', 68.1, -0.43, -0.64, '9/1 12:00am'],
31 ['General Electric Company', 34.14, -0.08, -0.23, '9/1 12:00am'],
32 ['General Motors Corporation', 30.27, 1.09, 3.74, '9/1 12:00am'],
33 ['Hewlett-Packard Co.', 36.53, -0.03, -0.08, '9/1 12:00am'],
34 ['Honeywell Intl Inc', 38.77, 0.05, 0.13, '9/1 12:00am'],
35 ['Intel Corporation', 19.88, 0.31, 1.58, '9/1 12:00am'],
36 ['International Business Machines', 81.41, 0.44, 0.54, '9/1 12:00am'],
37 ['Johnson & Johnson', 64.72, 0.06, 0.09, '9/1 12:00am'],
38 ['JP Morgan & Chase & Co', 45.73, 0.07, 0.15, '9/1 12:00am'],
39 ['McDonald\'s Corporation', 36.76, 0.86, 2.40, '9/1 12:00am'],
40 ['Merck & Co., Inc.', 40.96, 0.41, 1.01, '9/1 12:00am'],
41 ['Microsoft Corporation', 25.84, 0.14, 0.54, '9/1 12:00am'],
42 ['Pfizer Inc', 27.96, 0.4, 1.45, '9/1 12:00am'],
43 ['The Coca-Cola Company', 45.07, 0.26, 0.58, '9/1 12:00am'],
44 ['The Home Depot, Inc.', 34.64, 0.35, 1.02, '9/1 12:00am'],
45 ['The Procter & Gamble Company', 61.91, 0.01, 0.02, '9/1 12:00am'],
46 ['United Technologies Corporation', 63.26, 0.55, 0.88, '9/1 12:00am'],
47 ['Verizon Communications', 35.57, 0.39, 1.11, '9/1 12:00am'],
48 ['Wal-Mart Stores, Inc.', 45.45, 0.73, 1.63, '9/1 12:00am']
49 ];
50
51 //构造grid
52 var grid = new Ext.grid.GridPanel({
53 renderTo: "grid",
54 store: new Ext.data.ArrayStore({
55 fields: [
56 { name: 'company' },
57 { name: 'price', type: 'float' },
58 { name: 'change', type: 'float' },
59 { name: 'pctChange', type: 'float' },
60 { name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia' }
61 ],
62 data:myData
63 }),
64 cm: cm,
65 stripeRows: true,
66 autoExpandColumn: 'company',
67 height: 350,
68 width: 600,
69 title: 'Array Grid'
70 });
71})
renderTo:指出grid构造出来之后要在哪里呈现,可以是一个元素的id,一个Dom结点或者一个Element对象,如果没有这个参数,就必须调用Ext.grid.GridPanel的render方法来呈现出grid。
stroe:可以简写为ds,以一个统一的接口提供数据给grid,,我们知道数据可能有很多种格式,除了我们用到的数组,还可以是json,xml等等,如果让grid负责来识别每一种数据格式显然不是一个好的设计思想,所以在extjs中有一个专门的类Ext.data.Store来负责数据的格式转换,这里我们用到它的子类ArrayStore,顾名思义,是专门针对数组来进行转换的。我们会专门有一个系列来讨论Ext.data命名空间下边的一些类,那时会对Store类进行深入的了解。现在我们只看看我们用到的fields字段,它是Ext.data.Field类的集合,该类有一个name属性,我们前边在ColumnModel里边置之不理的dataIndex就是引用了这个属性的值来对应列和Field之间的关系,type用来指出类型,默认是字符串类型,dateFormat则指出日期的格式。
cm:colModel的简写,这里放上我们前边构造好的ColumnModel对象就可以了。
stripeRows:是否显示条纹。
autoExpandColumn:自动扩充的列,该列会自动填充grid的空白空间。
height和width:grid的高度和宽度。
title:grid的标题。
现在我们运行一下看看效果,应该说这个grid还算漂亮,在列的名字上点击还能够进行排序,列的宽度可以自由拖动,位置也可以改变。按下ctrl键,我们可以选择多个行。当我们把鼠标移动到列名上,还可以看到出现一个倒立的小三角,点击出现个菜单,可以看到里边能对列进行排序,还可以隐藏列。不过我们也看到,日期的显示并不尽如人意,百分比依然是浮点数,而且我们通常用赤字表示亏损或者现在更为流行的说法负增长,如果在我们的grid里边,负增长也可以用赤字表现出来,效果应该会更好一些。extjs给我们提供了一个很方便的东西来实现我们的想法:renderer。在ColumnModel里边,我们可以给需要的列里边增加renderer来实现我们想要的效果。下边是改动后的ColumnModel:
1 //构造列
2 var cm = new Ext.grid.ColumnModel([
3 { id: 'company', header: "Company", width: 160, sortable: true, dataIndex: 'company' },
4 { header: "Price", width: 75, sortable: true, dataIndex: 'price' },
5 { header: "Change", width: 75, sortable: true, dataIndex: 'change', renderer: change },
6 { header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange', renderer: pctChange },
7 { header: "Last Updated", width: 120, sortable: true, dataIndex: 'lastChange',renderer:Ext.util.Format.dateRenderer("Y-m-d h:i") }
8 ]);
9
10 // Change列的renderer函数
11 function change(val) {
12 if (val > 0) {
13 return '<span style="color:green;">' + val + '</span>';
14 } else if (val < 0) {
15 return '<span style="color:red;">' + val + '</span>';
16 }
17 return val;
18 }
19
20 // % Change列的renderer函数
21 function pctChange(val) {
22 if (val > 0) {
23 return '<span style="color:green;">' + val + '%</span>';
24 } else if (val < 0) {
25 return '<span style="color:red;">' + val + '%</span>';
26 }
27 return val;
28 }
renderer可以理解为一个“解释器”方法,它用来在显示数据之前转化数据。可以有三种方式来实现renderer:2 var cm = new Ext.grid.ColumnModel([
3 { id: 'company', header: "Company", width: 160, sortable: true, dataIndex: 'company' },
4 { header: "Price", width: 75, sortable: true, dataIndex: 'price' },
5 { header: "Change", width: 75, sortable: true, dataIndex: 'change', renderer: change },
6 { header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange', renderer: pctChange },
7 { header: "Last Updated", width: 120, sortable: true, dataIndex: 'lastChange',renderer:Ext.util.Format.dateRenderer("Y-m-d h:i") }
8 ]);
9
10 // Change列的renderer函数
11 function change(val) {
12 if (val > 0) {
13 return '<span style="color:green;">' + val + '</span>';
14 } else if (val < 0) {
15 return '<span style="color:red;">' + val + '</span>';
16 }
17 return val;
18 }
19
20 // % Change列的renderer函数
21 function pctChange(val) {
22 if (val > 0) {
23 return '<span style="color:green;">' + val + '%</span>';
24 } else if (val < 0) {
25 return '<span style="color:red;">' + val + '%</span>';
26 }
27 return val;
28 }
- 使用一个返回HTML标记的renderer函数
- Ext.util.Format类的一个属性,该属性提供一个renderer函数
- 一个包括renderer函数和作用域的对象
现在运行程序,可以看到我们希望的效果了:负增长用了赤字来表示,作为对比,正的增长用了绿颜色,时间也按照我们希望的格式显示了出来。
有的时候,我们还希望给每一行编号,这个实现起来也很容易,我们只要在ColumnModel的构造函数里边加上new Ext.grid.RowNumberer()就可以了:
1var cm = new Ext.grid.ColumnModel([
2 new Ext.grid.RowNumberer(), //实现自动编号
3 { id: 'company', header: "Company", width: 160, sortable: true, dataIndex: 'company' },
4 { header: "Price", width: 75, sortable: true, dataIndex: 'price' },
5 { header: "Change", width: 75, sortable: true, dataIndex: 'change', renderer: change },
6 { header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange', renderer: pctChange },
7 { header: "Last Updated", width: 120, sortable: true, dataIndex: 'lastChange',renderer:Ext.util.Format.dateRenderer("Y-m-d h:i") }
8 ]);
Ext.grid.GridPanel的配置里边还有两个常用的参数:2 new Ext.grid.RowNumberer(), //实现自动编号
3 { id: 'company', header: "Company", width: 160, sortable: true, dataIndex: 'company' },
4 { header: "Price", width: 75, sortable: true, dataIndex: 'price' },
5 { header: "Change", width: 75, sortable: true, dataIndex: 'change', renderer: change },
6 { header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange', renderer: pctChange },
7 { header: "Last Updated", width: 120, sortable: true, dataIndex: 'lastChange',renderer:Ext.util.Format.dateRenderer("Y-m-d h:i") }
8 ]);
viewConfig:我们可以用这个参数来对grid的界面进行一些设置,详细内容可以查看帮助文档。
selModel:可以简写为sm,选择模型,比如是选择单元格还是选择整个行,默认是选择行。