【问题标题】:How to calculate totals in a grid with the summary function如何使用汇总函数计算网格中的总数
【发布时间】:2023-04-03 04:55:02
【问题描述】:

我有一个包含两个汇总位置的网格。我在表格末尾有一个摘要。这很好用。但我想要的是计算每行的总价格。我有 4 列名为“Aantal、Stukprijs、korting 和 Totaal”。我需要的是在“Totaal”列中这个总和:(Aantal X Stukprijs) - %korting(means discount)。

这是该网格的代码:

  xtype: 'gridpanel',
                                id: 'materiaalGrid',
                                autoScroll: true,
                                forceFit: true,
                                store: 'MyArrayStore8',
                                columns: [
                                    {
                                        xtype: 'rownumberer'
                                    },
                                    {
                                        xtype: 'gridcolumn',
                                        dataIndex: 'naam',
                                        text: 'Naam',
                                        editor: {
                                            xtype: 'combobox'
                                        }
                                    },
                                    {
                                        xtype: 'gridcolumn',
                                        dataIndex: 'type',
                                        text: 'Type'
                                    },
                                    {
                                        xtype: 'numbercolumn',
                                        summaryType: 'sum',
                                        dataIndex: 'gewicht',
                                        text: 'Gewicht'
                                    },
                                    {
                                        xtype: 'numbercolumn',
                                        summaryType: 'sum',
                                        dataIndex: 'aantal',
                                        text: 'Aantal',
                                        editor: {
                                            xtype: 'numberfield'
                                        }
                                    },
                                    {
                                        xtype: 'numbercolumn',
                                        dataIndex: 'stuks',
                                        text: 'Stukprijs'
                                    },
                                    {
                                        xtype: 'numbercolumn',
                                        dataIndex: 'korting',
                                        text: 'Korting',
                                        editor: {
                                            xtype: 'numberfield',
                                            maxValue: 100
                                        }
                                    },
                                    {
                                        xtype: 'numbercolumn',
                                        summaryType: 'sum',
                                        dataIndex: 'stuks',
                                        text: 'Totaal'
                                    },
                                    {
                                        xtype: 'booleancolumn',
                                        dataIndex: 'verkoop',
                                        text: 'Verkoop'
                                    },
                                    {
                                        xtype: 'actioncolumn',
                                        maxWidth: 50,
                                        minWidth: 50,
                                        width: 50,
                                        defaultWidth: 50,
                                        emptyCellText: 'Delete',
                                        menuDisabled: true,
                                        items: [
                                            {
                                                handler: function(view, rowIndex, colIndex, item, e, record, row) {
                                                    var selection = me.getView().getSelectionModel().getSelection()[0];
                                                    if (selection) {
                                                        store.remove(selection);
                                                    }
                                                },
                                                altText: 'Delete'
                                            }
                                        ]
                                    }
                                ],
                                viewConfig: {
                                    enableTextSelection: false
                                },
                                features: [
                                    {
                                        ftype: 'summary'
                                    }
                                ],
                                plugins: [
                                    Ext.create('Ext.grid.plugin.RowEditing', {

                                    })
                                ],

我只能在最后一行得到 aantal 和 gewicht 的总和。

【问题讨论】:

    标签: extjs


    【解决方案1】:

    要解决此特定情况,您可以尝试这样做:

    • 对于“Aantal X Stukprijs”AKA 数量 X 单价(感谢上帝存在 Google 翻译器!)的结果,您可以创建一个计算字段来实现 convert 函数字段声明,如下:
    { 名称:“总计”, 类型:'数字', 转换:函数(值,记录){ 如果(!值){ // 只有在没有设置值的情况下才计算值 // 计算的总列将用一个真实的填充这个字段 // 我们不想弄乱的值 value = record.get('price') * record.get('units'); } 返回值; } }
    • 使用内联编辑器更改记录值时仍会出现不一致,您需要为此添加额外的处理程序,如下所示:
        grid.on('edit', function(editor, e) {
               // commit the changes right after editing finished    
               e.record.set('total'); // force total re-calculation
               e.record.commit(); 
       });
    

    你看到了complete example here,希望对你有帮助。

    【讨论】:

    • 转换部分完美!对于 grid.on 部分。我无法让它工作。我也尝试过建筑师,但似乎我把它放在了错误的位置
    • 您可以尝试在网格声明中添加侦听器,就像上一个示例的 modified version 一样
    猜你喜欢
    • 1970-01-01
    • 2012-02-28
    • 2019-08-18
    • 2018-06-06
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多