4

2 つの集計位置を持つグリッドがあります。グリッドの最後に要約があります。これはうまく機能しています。しかし、私が欲しいのは、行ごとの合計価格を計算することです。「Aantal、Stukprijs、korting、Totaal」という 4 つの列があります。私が必要としているのは、「Totaal」列にこの合計: (Aantal X Stukprijs) - %korting(割引を意味する) です。

これはそのグリッドのコードです:

  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 の合計しか取得できません。

4

1 に答える 1

4

この特定のシナリオを解決するには、次のことを試すことができます。

  • "Aantal X Stukprijs" AKA Quantity X Unit price (Google 翻訳者の存在に感謝します!)の結果については、次のように、フィールド宣言にconvert関数を実装する計算フィールドを作成できます。
{
        名前: '合計',
        タイプ: '数値',
        変換: 関数 (値、レコード) {
            if(!値) {
                // 値が設定されていない場合にのみ値を計算します
                // 計算された合計列は、このフィールドに実数を入力します
                // 混乱させたくない値
                値 = record.get('価格') * record.get('単位');
            }            
            戻り値;
        }
    }
  • インライン エディタを使用してレコードの値を変更すると、これでも不整合が残ります。次のように、そのための追加のハンドラを追加する必要があります。
    grid.on('edit', function(editor, e) {
           // commit the changes right after editing finished    
           e.record.set('total'); // force total re-calculation
           e.record.commit(); 
   });

ここに完全な例が表示されます。お役に立てば幸いです。

于 2013-10-17T13:47:19.113 に答える