Kendo Grid Footer Total (memo)

Source: Internet
Author: User
Effect Diagram:

Problem:
We can use Kendo datasource.aggregate to set which fields need to be aggregated, but some records cannot be excluded from the total (such as "free" record above)
Solution:
We can use a haystack to deal with, "amount total" binding is not Amount field totals, but the sum of another field, the problem can be resolved

xxx.editor.html
<style> ...
    /*grid footer Style */
. 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)" onclick= "Editorpage.removerow (This)" data-grid= "Grddetails" id= " Removerow "class=" Mini-button "><i class=" Icon-minus "></i></a>
         <a href=" javascript: void (0) "onclick=" 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; ...//Set the data source of the grid (note: Aggregate is to be used in conjunction with trigger ("change") in Dm.ondatachange) the//trigger ("Change") method ceases to be used because the grid
   Refresh, causing the picture to jump away from the modified 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"}]); Set the details grid to $ ("#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 "],//Add FooterTemplate Tag IDFor dynamic display of aggregate values//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.cot ei_net_amt.sum) #</span> "}, {field:" Cotei_share_amt ", Title:" Split ", width:80, Attributes: {style: "Text-align:right;"}, Format: "{0:n}", Editor:editors.com.price, aggregates: ["sum" ],//Add FooterTemplate tag ID for dynamic display of aggregate values FooterTemplate: "<span id= ' Cotei_share_amt ' class= ' fo Ot-num ' >#=kendo.format (' {0:n} ', sum) #</span> "}, ...], Datasource:datasource , Filterable:false, selectable: "Row", Pageable:false, Scrollable:true, resizable:t
   Rue, Navigatable:true, Editable:true,}); .....
}
Attention:
The FooterTemplate of the amount column above is bound to the total of the other field data.cotei_net_amt.sum

xxx.dm.js Code
Ondatachange:function (e) {      
    var dm = e.dm,
        row = E.row;
    ...
    if (e.action = = "ItemChange" && e.tablename = = "Ad_cont_expo_item") {
        ...
        Refresh Grid footer Totals field
        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));
    }}} ...
},
Because Datasource.aggregate seems to only open data and delete records to calculate the segment, if only the value of the field is not recalculated, so we have to manually refresh the real-time


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.