【问题标题】:devextream data grid Data Summaries Count the same datadevextreme datagrid 数据汇总 计算相同的数据
【发布时间】:2020-12-03 04:34:05
【问题描述】:

我正在使用 DevExtreme 并想使用汇总功能。 如果同一列有相同的数据,则统计

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;
                                }
                                
                            }
                        }
                    }
                   
                }
        },
.................

上面的结果是7 结果,您获得了相同数据的总数,但是当处理诸如网格按钮 desc 或 asc 之类的事件时,该数字会增加一倍。 看起来是这样,因为 calculateCustomSummary 已完成,之后它会在事件发生时继续触发。 应该如何处理?

【问题讨论】:

  • 如果你想有一个列的总数作为一个汇总,你的做法是正确的。应该计算相同的数据。

标签: javascript devextreme


【解决方案1】:

您使用的概念是正确的-您分配总值的方式包含一个小错误-至少从我对您提供的代码的理解来看。

你定义了数组 let te_arr = [];超出了 calculateCustomSummary 处理程序的范围,并且只有在满足所有条件时才将 data_state 推送给它。

但您并没有为每个 calculateCustomSummary 执行清除 te_arr。这就是为什么在一个事件之后你有 7 个,而在下一个事件之后你有 14 个。当 calculateCustomSummary 总结开始时,尝试修改你的 if 语句:

if (options.summaryProcess === "start") {
    options.totalValue = 0;
    te_arr = [];  
}

如果有效,请告诉我。

【讨论】:

  • 这个问题很久以前就解决了。如下 if (options.summaryProcess === "calculate") { //count++ if(options.value.PH_PayConfirm == 'Y'){ options.totalValue++; } } 如果有对应的值,立即相加,所以没有错误,推导出一个正常的值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-27
  • 2019-08-18
  • 1970-01-01
  • 2011-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多