【问题标题】:Setting cell value from SUM of other cells in the same row根据同一行中其他单元格的 SUM 设置单元格值
【发布时间】:2015-05-25 13:06:27
【问题描述】:

我有一个带有一些数字列的网格面板。我有一列将包含其他列的总和。当用户关注 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.)*/;
};

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

【问题讨论】:

    标签: javascript asp.net extjs ext.net gridpanel


    【解决方案1】:

    这是 ext.net 的重新设计答案。

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

    如果你想显示总和,你不需要使用编辑器。数字格式可以在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: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 */
    }
    

    【讨论】:

    • 您应该将其标记为正确答案。如果有人想寻找相同问题的解决方案,他们应该会看到“已回答”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-23
    • 2018-06-22
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    相关资源
    最近更新 更多