[EXTJS5 Study notes] 30th section Sencha ExtJS 5 table Gridpanel Grouping summary

Source: Internet
Author: User
Tags locale

This address: http://blog.csdn.net/sushengmiyan/article/details/42240531

This article Sushengmiyan

--------------------------------------------------------------------------------------------------------------- ---------------------

This paper, with a practical example, uses the grouping statistic display function in the Gridpanel of ExtJS, which involves the knowledge point:

Ext.grid.Panel features in the data grid in Model/store store and ftype: ' groupingsummary ', etc.

First, look at:


You can see that the installation month shown in the picture is grouped to show the totals and averages displayed under each grouping. My example is displayed normally in IE8 and Google Chrome and Firefox browsers.

Second, paste all the code (in fact, there is only one JSP page is enough)

<%@ page contenttype= "text/html; Charset=utf-8 "%><%string context = Request.getcontextpath ();%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >This is the name of a JSP can be.

It uses a date selection control and can only select the year of the month. And put the code on the way.

/** Months picker rewrite field. Date **/ext.define (' App.ux.Month ', {extend: ' Ext.form.field.Date ', alias: ' Widget.monthfield ', requires: [' E Xt.picker.Month '], alternateclassname: [' Ext.form.MonthField ', ' Ext.form.Month '], Selectmonth:null, createpic         Ker:function () {var me = this, format = Ext.String.format; Return ext.create (' Ext.picker.Month ', {pickerfield:me, ownerCt:me.ownerCt, Renderto  : Document.body, Floating:true, Hidden:true, Focusonshow:true, MinDate: Me.minvalue, MaxDate:me.maxValue, DisabledDatesRE:me.disabledDatesRE, disableddates             Text:me.disabledDatesText, DisabledDays:me.disabledDays, DisabledDaysText:me.disabledDaysText, Format:me.format, ShowToday:me.showToday, StartDay:me.startDay, Mintext : Format (Me.mintext, me.FormatDate (Me.minvalue)), Maxtext:format (Me.maxtext, Me.formatdate (Me.maxvalue)), listeners: {              Select: {scope:me, fn:me.onSelect}, Monthdblclick: {scope:me, Fn:me.onOKClick},     Yeardblclick: {scope:me, Fn:me.onOKClick}, Okclick: {scope:me, Fn:me.onOKClick                  }, Cancelclick: {scope:me, Fn:me.onCancelClick}}, Keynavconfig: {                 Esc:function () {me.collapse ();     }             }         });         }, Oncancelclick:function () {var me = this;         Me.selectmonth = null;     Me.collapse ();         }, Onokclick:function () {var me = this;             if (me.selectmonth) {me.setvalue (me.selectmonth);     Me.fireevent (' Select ', Me, me.selectmonth);     } me.collapse ();    }, Onselect:function (M, d) {var me = this;     Me.selectmonth = new Date ((d[0]+1) + '/1/' +d[1]);   }  });   /** Months Picker **/

Knowledge Point carding:

①. Show the data, here to tidy up some data, in practice, we can query the database to get, group queries can be.

   var data = [{             factory: ' First repair company ', Date: ' 2014-05 ', cost:52492.0, costav:52492.0      },{factory: ' Second maintenance company ', Date: ' 2014-05 ', cost:760.0, costav:760.0  },{factory: ' Third maintenance company ', Date: ' 2014-05 ', cost:1807.0, costav:1807.0  },{ Factory: ' First maintenance company ', Date: ' 2014-06 ', cost:4921.0, costav:4921.0  },{factory: ' Second maintenance company ', Date: ' 2014-06 ', cost:1020.0 , costav:1020.0  },{factory: ' Third maintenance company ', Date: ' 2014-06 ', cost:1637.0, costav:1637.0  },{factory: ' First maintenance company ', date : ' 2014-07 ', cost:48150.0, costav:48150.0  },{factory: ' Second maintenance company ', Date: ' 2014-07 ', cost:7940.0, costav:7940.0}];

②store Data interaction

   var store = ext.create (' Ext.data.Store ', {fields   : [{name: ' Date '}, {name: ' Cost '},{name: ' Costav '},{name: ' Factory ' }],                   GroupField: ' Date ',   data:data   });

You only need to specify a groupfield here, just this step.


③. Grid body

   var Grid = ext.create (' Ext.grid.Panel ', {frame:true,height:800,columnlines:true,//Plus table line features: [{ID: ' group ', Ftype: ' Groupingsummary ', Groupheadertpl: ' {name} ' + ' month car beauty and repair costs ', hidegroupedheader:false,enablegroupingmenu:false              }, {ftype: ' summary ', Summarytype: ' Average ', dock: ' Bottom '}], RenderTo:Ext.getBody (), columns: [{ Text: ' Repair time ', dataindex: ' Date ', width:100, summaryrenderer:function (value, Summarydata, dataindex) {retur n ' Total '}},{text: ' Maintenance fee (yuan) ', dataindex: ' Cost ', width:180, field: {xtype: ' Numberfield '}, Sum                              Marytype: ' Sum ', renderer:function (value, MetaData, record, Rowidx, COLIDX, store, view) {                              return value + ' meta '}, Summaryrenderer:function (value, Summarydata, Dataindex) { return value + ' meta '}},{text: ' Repair Factory ', Dataindex: ' Factory ', width:120, summaryrenderer:f Unction (value, Summarydata, dataIndex) {return ' average '}},{text: ', dataindex: ' Costav ', width:180, field: {xtype: ' Numberfield '}, Summarytype: ' Average ', renderer:function (value, MetaData, record, Rowidx, COLIDX, store, View) {return '},//this column finally shows the average value temporarily so the conversion shows summaryrenderer:function (value, Summarydata, data Index) {return value + ' meta '}}],store:store});

Note here that 1. You need to specify a height for the grid, if you do not specify IE8, the data is not displayed, it should be a bug.

2. Key to grouping and statistics

Features: [{ID: ' group ', ftype: ' groupingsummary ',//group statistics, you can choose not to group, various types can go to the API to find Groupheadertpl: ' {name} ' + ' month car beauty and maintenance costs ' ,//title just Hidegroupedheader:false,enablegroupingmenu:false}, {ftype: ' summary ',//summary below the Summarytype: ' Average ',// Type is averaged, and sum, etc., can go to the API to find the dock: ' Bottom '}],
Ok

In this way, you can simply implement a grouped report statistics, there are methods to find the average sum. Simple to use

[EXTJS5 Study notes] 30th section Sencha ExtJS 5 table Gridpanel Grouping summary

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.