效果图:
问题:
我们可以利用Kendo dataSource.aggregate设定哪些字段需要合计,但合计时无法排除某些记录(如上面的"Free"记录)
解决方案:
我们可以用一个掩眼法来处理, "Amount合计"绑定的不是Amount字段合计,而是另一个字段的合计,问题就可以解决了
xxx.editor.html
上面的Amount列的footerTemplate绑定的是另一字段的合计data.cotei_net_amt.sum
xxx.dm.js 代码
问题:
我们可以利用Kendo dataSource.aggregate设定哪些字段需要合计,但合计时无法排除某些记录(如上面的"Free"记录)
解决方案:
我们可以用一个掩眼法来处理, "Amount合计"绑定的不是Amount字段合计,而是另一个字段的合计,问题就可以解决了
xxx.editor.html
<style>
...
/*Grid Footer样式*/
.foot-num
{
display: inline-block;
width: 100%;
text-align: right;
}
...
</style>
...
<div id="tabDetails" style="height: 350px; padding-bottom: 5px;">
<div style="width: 100%; height: 20px;">
<a href="javascript:void(0)" οnclick="editorPage.removeRow(this)" data-grid="grdDetails" id="removeRow" class="mini-button"><i class="icon-minus"></i></a>
<a href="javascript:void(0)" οnclick="editorPage.addRow(this)" data-grid="grdDetails" id="addRow" class="mini-button"><i class="icon-plus"></i></a>
</div>
<div data-role="grid" id="grdDetails" style="height: 330px;"></div>
</div>
...
xxx.editor.js
onAfterCurrentChange: function (e) {
var dm = this;
...
//对Grid的数据源进行设置 (注意:aggregate要与dm.onDataChange中的trigger("change")结合使用)
//trigger("change")方法停止使用,因为会grid refresh,导致画面跳离修改处
var dataSource = dm.masterData.ad_cont_expo_item.dataSource;
dataSource.aggregate([
{ field: "cotei_net_amt", aggregate: "sum", totalField: "cote_item_amt" },
{ field: "cotei_share_amt", aggregate: "sum", totalField: "cote_item_share_amt" }
]);
//对Details Grid进行设置
$("#grdDetails").kendoGrid({
columns: [
{ field: "cotei_row_seq", title: "Row#", width: 50, editor: editors.int, footerTemplate: "Total" },
{ field: "expoi_no", title: "Code", width: 80, editor: editors.ad.expoitem_no },
...
{
field: "cotei_amt", title: "Amount", width: 80, attributes: { style: "text-align: right;" }, format: "{0:n}", editor: editors.readonly,
//aggregates: ["sum"],
//添加footerTemplate标签Id,用于动态显示合计值
//footerTemplate: "<span id='cotei_amt' class='foot-num'>#=kendo.format('{0:n}',sum)#</span>"
footerTemplate: "<span id='cotei_net_amt' class='foot-num'>#=kendo.format('{0:n}', data.cotei_net_amt.sum)#</span>"
},
{
field: "cotei_share_amt", title: "拆數", width: 80, attributes: { style: "text-align: right;" }, format: "{0:n}", editor: editors.com.price,
aggregates: ["sum"],
//添加footerTemplate标签Id,用于动态显示合计值
footerTemplate: "<span id='cotei_share_amt' class='foot-num'>#=kendo.format('{0:n}',sum)#</span>"
},
...
],
dataSource: dataSource,
filterable: false,
selectable: "row",
pageable: false,
scrollable: true,
resizable: true,
navigatable: true,
editable: true,
});
.....
}
注意:
上面的Amount列的footerTemplate绑定的是另一字段的合计data.cotei_net_amt.sum
xxx.dm.js 代码
onDataChange: function (e) {
var dm = e.dm,
row = e.row;
...
if (e.action == "itemchange" && e.tableName == "ad_cont_expo_item") {
...
//刷新Grid Footer合计字段
if (e.field === "cotei_net_amt" || e.field === "cotei_share_amt") {
var total = dm.masterData[e.tableName].dataSource._aggregateResult;
if (e.field in total) {
$("#" + e.field).html(kendo.format('{0:n}', total[e.field].sum));
}
}
}
...
},
由于DataSource.aggregate似乎只有打开数据和删除记录才会对段进行计算操作,如果只改字段的值是不会重算的,所以我们要手工进行实时刷新