Kendo Grid Footer的合计(备忘)

71 篇文章 2 订阅
效果图:

问题:
       我们可以利用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似乎只有打开数据和删除记录才会对段进行计算操作,如果只改字段的值是不会重算的,所以我们要手工进行实时刷新


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值