|
用户要求在表格中添加两个合计行,我在DEMO中似乎没有找到相关的实例。
于是参考http://www.fineui.com/bbs/forum. ... tid=1574&highlight=合计行
中的FineUI3的合计行JS版本改写如下,因为对ExtJS还处于摸索阶段,在防止重复添加合计行
那里卡住了,表格中显示的合计行出现重复添加的情况,请大家帮忙看看是哪里写的有问题,多谢了!
<script src="../res/js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
var gridClientID = '<%= Grid2.ClientID %>';
function calcGridSummary(grid) {
var G001bTotal = 0, store = grid.getStore(), view = grid.getView(), storeCount = store.getCount();
// 防止重复添加了合计行
//if (Ext.get(view.getNode(storeCount - 1)).hasClass('mygrid-row-summary')) {
// return;
//}
//console.log(view.getNode(storeCount - 1));
console.log(0);
if ($(view.getNode(0)).hasClass('mygrid-row-summary'))
{
console.log(2);
return;
}
// 遍历每一行数据,计算汇总数据
store.each(function (record) {
// 注:donate是列的ColumnID属性
if (record.get('TOTALb') == '保税区')
{
G001bTotal += parseInt(record.data["G001b"]);
}
});
Ext.regModel('pen', {
fields: [{
name: 'TOTALb',
type: 'string'
}, {
name: 'G001b',
type: 'auto'
}, {
name: 'G002b',
type: 'auto'
}, {
name: 'G003b',
type: 'auto'
}, {
name: 'G004b',
type: 'auto'
}],
});
var p = new pen({
TOTALb: '保税区合计',
G001b: G001bTotal,
G002b: G001bTotal,
G003b: G001bTotal,
G004b: G001bTotal
});
console.log(1);
store.insert(0, p);
//store.add(p);
// 为合计行添加自定义样式(隐藏序号列、复选框列,取消 hover 和 selected 效果)
$(view.getNode(0)).addClass('mygrid-row-summary');
console.log(view.getNode(0));
console.log(3);
}
// 页面第一个加载完毕后执行的函数
F.ready(function () {
var grid = F(gridClientID);
grid.addListener('viewready', function () {
calcGridSummary(grid);
});
// 防止选中合计行
grid.getSelectionModel().addListener('beforerowselect', function (sm, rowIndex, keepExisting, record) {
if ($(view.getNode(0)).hasClass('mygrid-row-summary')) {
return false;
}
return true;
});
console.log('ready');
});
// 页面AJAX回发后执行的函数
F.ajaxReady(function () {
var grid = F(gridClientID);
calcGridSummary(grid);
console.log('ajaxReady');
});
</script>
|
|