|
|
@@ -10,6 +10,25 @@ Ext.define('Ext.ux.feature.MySummary', {
|
|
|
|
|
|
showSummaryRow: true,
|
|
|
|
|
|
+ mySummaryTpl: [
|
|
|
+ '<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}',
|
|
|
+ '<tpl if="typeLabel">',
|
|
|
+ '({typeLabel})',
|
|
|
+ '</tpl>',
|
|
|
+ ': {value}',
|
|
|
+ '</div>',
|
|
|
+ '</td>',
|
|
|
+ '</tpl>',
|
|
|
+ '</tr>',
|
|
|
+ '</tbody>',
|
|
|
+ '</table>',
|
|
|
+ ],
|
|
|
+
|
|
|
init: function(grid) {
|
|
|
var me = this,
|
|
|
view = me.view,
|
|
|
@@ -42,24 +61,7 @@ Ext.define('Ext.ux.feature.MySummary', {
|
|
|
'{%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}',
|
|
|
- '<tpl if="typeLabel">',
|
|
|
- '({typeLabel})',
|
|
|
- '</tpl>',
|
|
|
- ': {value}',
|
|
|
- '</div>',
|
|
|
- '</td>',
|
|
|
- '</tpl>',
|
|
|
- '</tr>',
|
|
|
- '</tbody>',
|
|
|
- '</table>',
|
|
|
- ],
|
|
|
+ tpl: me.mySummaryTpl,
|
|
|
data: me.getSummarys(),
|
|
|
height: 36,
|
|
|
scrollable: {
|
|
|
@@ -83,63 +85,7 @@ Ext.define('Ext.ux.feature.MySummary', {
|
|
|
});
|
|
|
|
|
|
store.on('load', function( s, records, successful, operation, eOpts) {
|
|
|
- var _res = operation._response.responseJson,
|
|
|
- _calculateProperty = grid.calculateProperty,
|
|
|
- _rootProperty = grid.rootProperty;
|
|
|
-
|
|
|
- var _root = _calculateProperty.split('.')[0];
|
|
|
- eval('var ' + _root + ' = _res[_root];');
|
|
|
- try {
|
|
|
- var columns = grid.columns,
|
|
|
- summaryData = [],
|
|
|
- datas = [];
|
|
|
- try {
|
|
|
- summaryData = eval(_calculateProperty);
|
|
|
- datas = eval(_rootProperty);
|
|
|
-
|
|
|
- if(!Ext.isArray(summaryData)) {
|
|
|
- summaryData = [];
|
|
|
- }
|
|
|
- if(!Ext.isArray(datas)) {
|
|
|
- datas = [];
|
|
|
- }
|
|
|
- }catch(e) {
|
|
|
- // don't care this...
|
|
|
- }
|
|
|
- Ext.Array.each(columns, function (c) {
|
|
|
- var type = c._summaryType,
|
|
|
- name = c.dataIndex;
|
|
|
-
|
|
|
- var d = Ext.Array.findBy(summaryData, function (s) {
|
|
|
- return s.hasOwnProperty(name);
|
|
|
- })
|
|
|
- if (type && d) {
|
|
|
- if(typeof c.mySummaryRenderer == 'function') {
|
|
|
- c.summaryValue = c.mySummaryRenderer(grid, c, datas);
|
|
|
- }else if (type == 'count') {
|
|
|
- c.summaryValue = Ext.util.Format.number(d[name], c.format || '0');
|
|
|
- } else if (typeof c.summaryRenderer == 'function') {
|
|
|
- c.summaryValue = c.summaryRenderer(d[name]);
|
|
|
- } else if (typeof c.renderer == 'function') {
|
|
|
- c.summaryValue = c.renderer(d[name]);
|
|
|
- } else {
|
|
|
- c.summaryValue = Ext.util.Format.number(d[name], c.format || '0.00');
|
|
|
- }
|
|
|
- } else if(type && !d) {
|
|
|
- if(typeof c.mySummaryRenderer == 'function') {
|
|
|
- c.summaryValue = c.mySummaryRenderer(grid, c, datas);
|
|
|
- }else {
|
|
|
- c.summaryValue = me.applySummaryValue(datas, c);
|
|
|
- }
|
|
|
- } else {
|
|
|
- c.summaryValue = null;
|
|
|
- }
|
|
|
- });
|
|
|
- return datas;
|
|
|
- } catch (e) {
|
|
|
- console.error(e);
|
|
|
- saas.util.BaseUtil.showErrorToast(e.message);
|
|
|
- }
|
|
|
+ me.applySummarys(operation._response.responseJson);
|
|
|
});
|
|
|
|
|
|
me.bindStore(grid, store);
|
|
|
@@ -245,6 +191,69 @@ Ext.define('Ext.ux.feature.MySummary', {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ // 处理后台返回的合计数据,默认将合计值赋予对应列
|
|
|
+ applySummarys: function(response) {
|
|
|
+ var me = this,
|
|
|
+ grid = me.grid;
|
|
|
+ var _res = response,
|
|
|
+ _calculateProperty = grid.calculateProperty,
|
|
|
+ _rootProperty = grid.rootProperty;
|
|
|
+
|
|
|
+ var _root = _calculateProperty.split('.')[0];
|
|
|
+ eval('var ' + _root + ' = _res[_root];');
|
|
|
+ try {
|
|
|
+ var columns = grid.columns,
|
|
|
+ summaryData = [],
|
|
|
+ datas = [];
|
|
|
+ try {
|
|
|
+ summaryData = eval(_calculateProperty);
|
|
|
+ datas = eval(_rootProperty);
|
|
|
+
|
|
|
+ if(!Ext.isArray(summaryData)) {
|
|
|
+ summaryData = [];
|
|
|
+ }
|
|
|
+ if(!Ext.isArray(datas)) {
|
|
|
+ datas = [];
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ // don't care this...
|
|
|
+ }
|
|
|
+ Ext.Array.each(columns, function (c) {
|
|
|
+ var type = c._summaryType,
|
|
|
+ name = c.dataIndex;
|
|
|
+
|
|
|
+ var d = Ext.Array.findBy(summaryData, function (s) {
|
|
|
+ return s.hasOwnProperty(name);
|
|
|
+ })
|
|
|
+ if (type && d) {
|
|
|
+ if(typeof c.mySummaryRenderer == 'function') {
|
|
|
+ c.summaryValue = c.mySummaryRenderer(grid, c, datas);
|
|
|
+ }else if (type == 'count') {
|
|
|
+ c.summaryValue = Ext.util.Format.number(d[name], c.format || '0');
|
|
|
+ } else if (typeof c.summaryRenderer == 'function') {
|
|
|
+ c.summaryValue = c.summaryRenderer(d[name]);
|
|
|
+ } else if (typeof c.renderer == 'function') {
|
|
|
+ c.summaryValue = c.renderer(d[name]);
|
|
|
+ } else {
|
|
|
+ c.summaryValue = Ext.util.Format.number(d[name], c.format || '0.00');
|
|
|
+ }
|
|
|
+ } else if(type && !d) {
|
|
|
+ if(typeof c.mySummaryRenderer == 'function') {
|
|
|
+ c.summaryValue = c.mySummaryRenderer(grid, c, datas);
|
|
|
+ }else {
|
|
|
+ c.summaryValue = me.applySummaryValue(datas, c);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ c.summaryValue = null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return datas;
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
+ saas.util.BaseUtil.showErrorToast(e.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
applySummaryValue: function(datas, c) {
|
|
|
var dataIndex = c.dataIndex,
|
|
|
type = c.summaryType,
|