上星期五,在写一个Grid,里面有一个金额的字段需要进行统计,代码如下:
Ext.define('book',{
extend: 'Ext.data.Model',
fields: [
{name: 'bookname'},
{name: 'bookprice'},
{name: 'author'}
]
});
var bookstore = Ext.create('Ext.data.Store',{
model: 'book',
autoLoad: true,
buffered: true,
proxy: {
type: 'ajax',
url: 'books.json',
reader: {
type: 'json',
root: 'bookList'
}
}
});
.................
................
{
xtype: 'grid',
store: bookstore,
title: 'books',
columnLines: true,
frame: false,
padding: '5 5 5 5',
enableColumnHide :false,
selType: 'rowmodel',
height: 500,
width: '100%',
plugins: 'bufferedrenderer',
features: [
{ftype: 'summary'}
],
//dockedItems:[pageInfo],
viewConfig: {
forceFit: true,
stripeRows: true,
scrollDelta: 160
},
columns: [
Ext.create('Ext.grid.RowNumberer',{text: 'No', width: 52}),
{ text: '书名', dataIndex: 'bookname',width: 400, sortable: false },
{ text: '金额', dataIndex: 'bookprice',align: 'right', xtype: 'numbercolumn', format: '0,000.00', width: 130, sortable: false,
summaryType: 'sum',
summaryRenderer: function(value){
Ext.util.Format.thousandSeparator= ',';
Ext.util.Format.decimalSeparator='.';
return '合计:'+Ext.util.Format.number(value, '0,000.00')
}
},
{ text: '作者', dataIndex: 'author',width: 130, sortable: false },
.....................
.....................
books.json内容如下:
bookList:[
{bookname: 'java从入门到精通', bookprice: 56.40},
{bookname: 'java Web编程', bookprice: 72.30},
{bookname: 'Python Web编程', bookprice: 32.30},
{bookname: 'Javascript高级程序设计', bookprice: 93.20}
]}
以上代码,运行时却显示不出结果,出错信息如下图:
后来将store的buffered:true,改成false,或删除,则运行正常。
如何使用buffered, 请参看 http://blog.csdn.net/wilsonyun/article/details/46513881