|
|
@@ -0,0 +1,180 @@
|
|
|
+Ext.define('Ext.ux.feature.MySummary', {
|
|
|
+
|
|
|
+ /* Begin Definitions */
|
|
|
+
|
|
|
+ extend: 'Ext.grid.feature.AbstractSummary',
|
|
|
+
|
|
|
+ alias: 'feature.mysummary',
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @cfg {String} dock
|
|
|
+ * Configure `'top'` or `'bottom'` top create a fixed summary row either above or below the scrollable table.
|
|
|
+ *
|
|
|
+ */
|
|
|
+ dock: undefined,
|
|
|
+
|
|
|
+ summaryItemCls: Ext.baseCSSPrefix + 'grid-row-mysummary-item',
|
|
|
+ dockedSummaryCls: Ext.baseCSSPrefix + 'docked-mysummary',
|
|
|
+
|
|
|
+ summaryRowCls: Ext.baseCSSPrefix + 'grid-row-summary ' + Ext.baseCSSPrefix + 'grid-row-total',
|
|
|
+ summaryRowSelector: '.' + Ext.baseCSSPrefix + 'grid-row-summary.' + Ext.baseCSSPrefix + 'grid-row-total',
|
|
|
+
|
|
|
+ // turn off feature events.
|
|
|
+ hasFeatureEvent: false,
|
|
|
+
|
|
|
+ init: function(grid) {
|
|
|
+ var me = this,
|
|
|
+ view = me.view,
|
|
|
+ dock = me.dock,
|
|
|
+ summarys = me.getSummarys(grid);
|
|
|
+
|
|
|
+ me.callParent([grid]);
|
|
|
+
|
|
|
+ // var mySummaryStore = grid.mySummaryStore = Ext.create('Ext.data.Store', {
|
|
|
+ // fields: ['name', 'label', 'typeLabel', 'type', 'value'],
|
|
|
+ // data: [{
|
|
|
+ // name: 'xxx',
|
|
|
+ // label: '111',
|
|
|
+ // type: 'sum',
|
|
|
+ // value: 0
|
|
|
+ // }]
|
|
|
+ // });
|
|
|
+
|
|
|
+ grid.on({
|
|
|
+ mysummarychange: me.refreshData,
|
|
|
+ scope: me
|
|
|
+ });
|
|
|
+
|
|
|
+ grid.on({
|
|
|
+ beforerender: function() {
|
|
|
+ var tableCls = [me.summaryTableCls];
|
|
|
+ if (view.columnLines) {
|
|
|
+ tableCls[tableCls.length] = view.ownerCt.colLinesCls;
|
|
|
+ }
|
|
|
+ me.summaryBar = grid.addDocked({
|
|
|
+ childEls: ['innerCt', 'item'],
|
|
|
+ renderTpl: [
|
|
|
+ '<div id="{id}-innerCt" data-ref="innerCt" role="presentation">',
|
|
|
+ '{%this.renderContent(out,values)%}',
|
|
|
+ '</div>'
|
|
|
+ ],
|
|
|
+ tpl: [
|
|
|
+ '<table class="x-grid-row-mysummary">',
|
|
|
+ '<tbody>',
|
|
|
+ '<tr>',
|
|
|
+ '<tpl for=".">',
|
|
|
+ '<td class="x-grid-cell x-grid-td x-grid-cell-numbercolumn-1526 x-unselectable x-mysummary-item">' +
|
|
|
+ '<div class="x-grid-cell-inner x-mysummary-item-cell">{label}({typeLabel}): {value}</div>' +
|
|
|
+ '</td>',
|
|
|
+ '</tpl>',
|
|
|
+ '</tr>',
|
|
|
+ '</tbody>',
|
|
|
+ '</table>',
|
|
|
+ ],
|
|
|
+ data: summarys,
|
|
|
+ scrollable: {
|
|
|
+ x: false,
|
|
|
+ y: false
|
|
|
+ },
|
|
|
+ hidden: !me.showSummaryRow,
|
|
|
+ itemId: 'mysummaryBar',
|
|
|
+ cls: [ me.dockedSummaryCls, me.dockedSummaryCls + '-' + dock ],
|
|
|
+ xtype: 'component',
|
|
|
+ dock: dock,
|
|
|
+ weight: 10000000
|
|
|
+ })[0];
|
|
|
+ },
|
|
|
+ single: true
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getSummarys: function(grid) {
|
|
|
+ var me = this,
|
|
|
+ summarys = [],
|
|
|
+ columns = grid.columns;
|
|
|
+
|
|
|
+ var typeLabels = {
|
|
|
+ sum: '合计',
|
|
|
+ count: '计数',
|
|
|
+ avg: '平均值',
|
|
|
+ max: '最大值',
|
|
|
+ min: '最小值'
|
|
|
+ };
|
|
|
+
|
|
|
+ Ext.Array.each(columns, function(c) {
|
|
|
+ if(c.summaryType) {
|
|
|
+ summarys.push({
|
|
|
+ name: c.dataIndex,
|
|
|
+ label: c.text,
|
|
|
+ type: c.summaryType,
|
|
|
+ typeLabel: typeLabels[c.summaryType],
|
|
|
+ value: c.summaryValue || 0
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ grid.summarys = summarys;
|
|
|
+
|
|
|
+ return summarys;
|
|
|
+ },
|
|
|
+
|
|
|
+ refreshData: function(grid) {
|
|
|
+ var me = this,
|
|
|
+ summaryBar = me.summaryBar,
|
|
|
+ newSummarys = me.getSummarys(grid);
|
|
|
+
|
|
|
+ summaryBar.update(newSummarys);
|
|
|
+
|
|
|
+ // if (!view.rendered) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // record = me.createSummaryRecord(view);
|
|
|
+ // newRowDom = Ext.fly(view.createRowElement(record, -1)).down(selector, true);
|
|
|
+
|
|
|
+ // if (!newRowDom) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // Summary row is inside the docked summaryBar Component
|
|
|
+ // if (dock) {
|
|
|
+ // p = me.summaryBar.item.dom.firstChild;
|
|
|
+ // oldRowDom = p.firstChild;
|
|
|
+
|
|
|
+ // p.insertBefore(newRowDom, oldRowDom);
|
|
|
+ // p.removeChild(oldRowDom);
|
|
|
+ // }
|
|
|
+ // // Summary row is a regular row in a THEAD inside the View.
|
|
|
+ // // Downlinked through the summary record's ID
|
|
|
+ // else {
|
|
|
+ // oldRowDom = view.el.down(selector, true);
|
|
|
+ // p = oldRowDom && oldRowDom.parentNode;
|
|
|
+
|
|
|
+ // if (p) {
|
|
|
+ // p.removeChild(oldRowDom);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // We're always inserting the new summary row into the last rendered row,
|
|
|
+ // // unless no rows exist. In that case we will be appending to the special
|
|
|
+ // // placeholder in the node container.
|
|
|
+ // p = view.getRow(view.all.last());
|
|
|
+
|
|
|
+ // if (p) {
|
|
|
+ // p = p.parentElement;
|
|
|
+ // }
|
|
|
+ // // View might not have nodeContainer yet.
|
|
|
+ // else {
|
|
|
+ // p = me.getSummaryRowPlaceholder(view);
|
|
|
+ // p = p && p.tBodies && p.tBodies[0];
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (p) {
|
|
|
+ // p.appendChild(newRowDom);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ },
|
|
|
+
|
|
|
+ getSummaryBar: function() {
|
|
|
+ return this.summaryBar;
|
|
|
+ },
|
|
|
+});
|