1、定义model
Ext.define('report', {
extend: 'Ext.data.Model',
fields: [ { name: 'customerName', type: 'string' },
{ name: 'Name', type: 'number' },
{ name: 'Quantity', type: 'number' },
{ name: 'Price', type: 'string' }
]
});
2、创建store
reportStore = Ext.create('Ext.data.Store', {
model: 'report',
data: []
});
3、创建grid
grid = Ext.create('Ext.grid.Panel', {
renderTo: 'grid',
store: reportStore,
header:false,
width: '100%',
columns: [{text: "序号", xtype: 'rownumberer',width: 80,align:'left'},
{
text: '名称',
flex: 1,
dataIndex: 'customerName'
},{
text: '销售人',
flex: 1,
dataIndex: 'Name'
},
{
text: '销售量',
flex: 1,
dataIndex: 'Quantity',
xtype: 'numbercolumn',
format: '0.00',
},{
text: '销售金额',
flex: 1,
dataIndex: 'Price',
xtype: 'numbercolumn',
format: '0.00',
}
]
});
4、在grid中各配置项含义:
- text: '销售量',//显示的we
- flex: 1,//自动适应的宽度
- dataIndex: 'documentQuantity',//绑定字段的名字
- xtype: 'numbercolumn',//列的类型
- format: '0.00', //格式化 此处是将数字格式化为 保留两位小数。
附上网上搜的常用配置项:
- xtype:列类型
- text:列头显示的文字
- dataIndex:绑定的字段名
- width:宽度
- flex:自动适应的宽度
- sortable:是否可排序,默认为是
- hideable:是否可隐藏,默认为是
- locked:锁定列,将列锁定在grid的开头,当grid出现滚动条的时候该属性比较有用。默认为否
- lockable:是否可锁定,默认为否
- format:格式化字符串,常用于日期、数字的格式化。日期:'Y-m-d';日期时间:'Y-m-d H:i:s';数字:'0,000.00'(带有千位分隔符、保留两位小数)、'0.00'(保留两位小数),'0'(不保留小数)
- renderer:自定义绘制方法,可以是Ext.util.Format中定义好的方法名称,也可以是自定义否function,该方法接收下面的参数:value、metadata、record、rowIndex、colIndex、store、view,并需要一个用来显示的返回值。
- editor:编辑器,当使用编辑插件的时候才会起作用。