从同一行中其他单元格的SUM中设置单元格值

Setting cell value from SUM of other cells in the same row

本文关键字:单元格 其他 SUM 设置 一行      更新时间:2023-09-26

我有一个gridpanel与一些数字列。我有一列将包含其他列的和。我想在用户关注SUM列时自动设置此值。下面是我的代码:

<ext:Column runat="server"
    DataIndex="totalth"
    Text="TOTAL (T/H)"
    Flex="2"
    Align="Center">
        <Editor>
            <ext:NumberField
                runat="server"
                AllowBlank="false"
                AllowDecimals="true"
                DecimalPrecision="3"
                name="totalth"
                Step="0.01">
                    <Listeners>
                        <Focus Fn="getSum"></Focus>
                    </Listeners>
            </ext:NumberField>
        </Editor>
</ext:Column>
Javascript Fn:

var getSum = function (item) {
    item.setValue/*(here is the sum of other two cells in the same row.)*/;
};

如何从其他单元格中获取值?也许在服务器端做会更好,我不知道。

这是一个针对ext.net的重新设计的答案。

您仍然可以使用renderer,因为它与记录一起工作。如果你只想在某些动作上显示它,有很多方法可以做到这一点。就像鼠标悬停一样,您可以使用overCls使用CSS隐藏文本,就像我在示例中所做的那样。

如果你想显示sum,你不需要使用editor。数字格式可以在getSum渲染器中处理。

Javascript:

var getSum = function ( value, metadata, record ) {
    var sum = record.get( 'column1' ) + record.get( 'column2' )
    return sum.toFixed( 2 ); // to show 2 decimal places
}
Ext.net:

<ext:Column runat="server"
    DataIndex="totalth"
    Text="TOTAL (T/H)"
    Flex="2"
    Align="Center"
    cls="column-hidden"
    overCls="column-shown">
        <Renderer Fn="getSum" />
CSS:

x-column-hidden { /* x- prefix needed depending on your version */
    /* style to hide your text */
}
x-column-shown {
    /* style to cancel hiding */
}