I am using DevExtreme and want to use the summary function. If there is the same data in the same column, it is counted
let te_arr = [];
dxDataGrid({
..................
columns: [
{ dataField: "columnsTest", caption: "columnsTest"}
],
summary: {
recalculateWhileEditing: true,
totalItems: [
{
name: "SelectedRowsSummary",
showInColumn: "columnsTest",
displayFormat: "count: {0}",
summaryType: "custom"
}],
calculateCustomSummary: function (options) {
if(options.value){
let data_state = options.value.columndata
console.log('data_state ',data_state );
if (options.name == "SelectedRowsSummary") {
if (options.summaryProcess === "start") {
options.totalValue = 0;
}
if (options.summaryProcess === "calculate") {
if (data_state == 'Y') {
te_arr.push(data_state );
options.totalValue = te_arr.length;
}
}
}
}
}
},
.................
The above result is a count of 7 As a result you get the total count of the same data, but when an event like a grid button desc or asc is handled, the number is doubled. It seems like that because calculateCustomSummary is complete and after that it continues to fire when the event occurs. How should it be handled?
The concept you are using is correct - the way how you assign total value contains a small error – at least from my understanding of the code you provided.
You defined array let te_arr = []; outside of scope on calculateCustomSummary handler, and you are only pushing data_state to it if all your conditions are met.
But you are not clearing te_arr, for each calculateCustomSummary execution. That why after one event you have 7, and after the next one you have 14. Try to modify your if statement when calculateCustomSummary summary is starting to this :
if (options.summaryProcess === "start") {
options.totalValue = 0;
te_arr = [];
}
Please let me know if it works.