test calcular subtotales por grupo de filas
This commit is contained in:
parent
be3b66ebae
commit
45bdad3d8c
@ -107,6 +107,9 @@ function makeRenderer() {
|
|||||||
beforeFirstKey = currentFirstKey;
|
beforeFirstKey = currentFirstKey;
|
||||||
}
|
}
|
||||||
rowKeysSub.push(arrRowKeys);
|
rowKeysSub.push(arrRowKeys);
|
||||||
|
if (idx === rowKeys.length - 1) {
|
||||||
|
rowKeysSub.push([currentFirstKey, '[:sub-total:]']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rowKeysSub = pivotData.getRowKeys();
|
rowKeysSub = pivotData.getRowKeys();
|
||||||
@ -384,14 +387,13 @@ function makeRenderer() {
|
|||||||
'tbody',
|
'tbody',
|
||||||
null,
|
null,
|
||||||
rowKeysSub.map(function (rowKey, i) {
|
rowKeysSub.map(function (rowKey, i) {
|
||||||
|
|
||||||
var isSubTotal = rowKey.includes('[:sub-total:]');
|
var isSubTotal = rowKey.includes('[:sub-total:]');
|
||||||
var totalAggregator = isSubTotal ? { value: function value() {
|
var totalAggregator = isSubTotal ? { value: function value() {
|
||||||
return 0;
|
return 0;
|
||||||
} } : pivotData.getAggregator(rowKey, []);
|
} } : pivotData.getAggregator(rowKey, []);
|
||||||
return _react2.default.createElement(
|
return _react2.default.createElement(
|
||||||
'tr',
|
'tr',
|
||||||
{ key: 'rowKeyRow' + i },
|
{ key: 'rowKeyRow' + i + ' ' + (isSubTotal ? ' bg-sky-50 ' : '') },
|
||||||
rowKey.map(function (txt, j) {
|
rowKey.map(function (txt, j) {
|
||||||
var x = spanSize(rowKeysSub, i, j);
|
var x = spanSize(rowKeysSub, i, j);
|
||||||
if (x === -1) {
|
if (x === -1) {
|
||||||
@ -406,13 +408,11 @@ function makeRenderer() {
|
|||||||
rowSpan: x,
|
rowSpan: x,
|
||||||
colSpan: j === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1
|
colSpan: j === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1
|
||||||
},
|
},
|
||||||
txt
|
isSubTotal ? 'SubTotal' : txt
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
colKeys.map(function (colKey, j) {
|
colKeys.map(function (colKey, j) {
|
||||||
var aggregator = isSubTotal ? { value: function value() {
|
var aggregator = pivotData.getAggregator(rowKey, colKey);
|
||||||
return 0;
|
|
||||||
} } : pivotData.getAggregator(rowKey, colKey);
|
|
||||||
return _react2.default.createElement(
|
return _react2.default.createElement(
|
||||||
'td',
|
'td',
|
||||||
{
|
{
|
||||||
@ -421,7 +421,7 @@ function makeRenderer() {
|
|||||||
onClick: getClickHandler && getClickHandler(aggregator.value(), rowKey, colKey),
|
onClick: getClickHandler && getClickHandler(aggregator.value(), rowKey, colKey),
|
||||||
style: valueCellColors(rowKey, colKey, aggregator.value())
|
style: valueCellColors(rowKey, colKey, aggregator.value())
|
||||||
},
|
},
|
||||||
isSubTotal ? 'a' : getFormatedValue(aggregator)
|
getFormatedValue(aggregator)
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
_react2.default.createElement(
|
_react2.default.createElement(
|
||||||
@ -431,7 +431,7 @@ function makeRenderer() {
|
|||||||
onClick: getClickHandler && getClickHandler(totalAggregator.value(), rowKey, [null]),
|
onClick: getClickHandler && getClickHandler(totalAggregator.value(), rowKey, [null]),
|
||||||
style: colTotalColors(totalAggregator.value())
|
style: colTotalColors(totalAggregator.value())
|
||||||
},
|
},
|
||||||
isSubTotal ? 'a' : getFormatedValue(totalAggregator)
|
isSubTotal ? '' : getFormatedValue(totalAggregator)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
File diff suppressed because one or more lines are too long
45
Utilities.js
45
Utilities.js
@ -850,9 +850,54 @@ var PivotData = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'getAggregator',
|
key: 'getAggregator',
|
||||||
value: function getAggregator(rowKey, colKey) {
|
value: function getAggregator(rowKey, colKey) {
|
||||||
|
var _this5 = this;
|
||||||
|
|
||||||
var agg = void 0;
|
var agg = void 0;
|
||||||
var flatRowKey = rowKey.join(String.fromCharCode(0));
|
var flatRowKey = rowKey.join(String.fromCharCode(0));
|
||||||
var flatColKey = colKey.join(String.fromCharCode(0));
|
var flatColKey = colKey.join(String.fromCharCode(0));
|
||||||
|
if (rowKey.includes('[:sub-total:]')) {
|
||||||
|
var _resultAgg = {};
|
||||||
|
var arrRowKeys = this.rowKeys.filter(function (itmRk) {
|
||||||
|
return itmRk[0] === rowKey[0];
|
||||||
|
});
|
||||||
|
var subTotalBruto = 0;
|
||||||
|
var subTotalCount = arrRowKeys.length;
|
||||||
|
var subTotalMin = null;
|
||||||
|
var subTotalMax = null;
|
||||||
|
for (var idx = 0; idx < subTotalCount; idx++) {
|
||||||
|
var _rowKey = arrRowKeys[idx];
|
||||||
|
var _agg = this.getAggregator(_rowKey, colKey);
|
||||||
|
var _aggValue = _agg.value();
|
||||||
|
subTotalBruto = subTotalBruto + _aggValue;
|
||||||
|
if (idx === 0) {
|
||||||
|
subTotalMin = _aggValue;
|
||||||
|
subTotalMax = _aggValue;
|
||||||
|
} else {
|
||||||
|
subTotalMin = _aggValue < subTotalMin ? _aggValue : subTotalMin;
|
||||||
|
subTotalMax = _aggValue > subTotalMax ? _aggValue : subTotalMax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_resultAgg.sum = subTotalBruto;
|
||||||
|
_resultAgg.count = subTotalCount;
|
||||||
|
_resultAgg.value = function () {
|
||||||
|
if (_this5.props.aggregatorName === 'Conteo') {
|
||||||
|
return subTotalCount;
|
||||||
|
}
|
||||||
|
if (_this5.props.aggregatorName === 'Suma') {
|
||||||
|
return subTotalBruto;
|
||||||
|
}
|
||||||
|
if (_this5.props.aggregatorName === 'Promedio') {
|
||||||
|
return subTotalBruto / subTotalCount;
|
||||||
|
}
|
||||||
|
if (_this5.props.aggregatorName === 'Mínimo') {
|
||||||
|
return subTotalMin;
|
||||||
|
}
|
||||||
|
if (_this5.props.aggregatorName === 'Máximo') {
|
||||||
|
return subTotalMax;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
if (rowKey.length === 0 && colKey.length === 0) {
|
if (rowKey.length === 0 && colKey.length === 0) {
|
||||||
agg = this.allTotal;
|
agg = this.allTotal;
|
||||||
} else if (rowKey.length === 0) {
|
} else if (rowKey.length === 0) {
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "v-react-pivottable",
|
"name": "v-react-pivottable",
|
||||||
"version": "0.11.51",
|
"version": "0.11.52",
|
||||||
"description": "A React-based pivot table",
|
"description": "A React-based pivot table",
|
||||||
"main": "PivotTableUI.js",
|
"main": "PivotTableUI.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
Loading…
Reference in New Issue
Block a user