【问题标题】:How to query summary/group in devexpress with advanced queries如何使用高级查询在 devexpress 中查询摘要/组
【发布时间】:2013-09-06 17:49:44
【问题描述】:

一个简单的查询:

var viewModel = {
    dataSource: Application_with_Chart.db.nom_clasa_articole.toDataSource({
        select: ["id","product", "quantity"]
    })
};

return viewModel;

在 SQL 中:

SELECT id,product,quantity
FROM nom_clasa_articole

这很简单,但我需要一个带有 group by 和 sum 的查询:

SELECT id, product, SUM(quantity)
FROM nom_clasa_articole
GROUP BY product

如何在 devexpress 中编写此查询?

【问题讨论】:

    标签: javascript jquery devexpress phonejs


    【解决方案1】:

    如果我没记错的话,问题是关于DevExtreme Multi-channel applications。他们使用 OData 服务。

    OData prodocol 没有直接等效于 SQL GROUP BY。您有两种选择:

    1. 在服务器端使用OData service operations进行分组。

    2. postProcess 处理程序中对客户端执行分组,如下所示。

    客户端分组:

    var viewModel = {
        dataSource: Application32.db.nom_clasa_articole.toDataSource({
            select: ["id", "product", "quantity"],
    
            postProcess: function(items) {
                // Grouping occurs here
                var groups = {};
    
                $.each(items, function() {
                    var groupKey = this.product;
                    if(!groups[groupKey])
                        groups[groupKey] = { quantity: 0 };
    
                    groups[groupKey].quantity += this.quantity;
                });
    
                return $.map(groups, function(v, k) { 
                    return { product: k, quantity: v.quantity }; 
                });
            }
        })
    };
    

    【讨论】:

    • 怎么做这样的事情:SELECT * FROM PEOPLE WHERE NAME='JACK'?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 2010-11-01
    • 1970-01-01
    • 2020-03-15
    • 2016-02-01
    • 2014-02-22
    • 2012-10-19
    相关资源
    最近更新 更多