【问题标题】:How can we set color for particular column filed value conditionally in Acumatica我们如何在 Acumatica 中有条件地为特定列字段值设置颜色
【发布时间】:2020-05-20 20:39:24
【问题描述】:

我需要根据条件为网格列设置颜色。 例如:我在网格中有两个字段 1.销售价格 2. 新销售 如果销售价格和新销售价值相同,我想显示绿色 否则,如果销售价格高于新销售,则显示红色 否则,如果销售价格低于新销售,则希望显示黄色。

这不是一个通用的查询屏幕,这就像在标题中使用 FormDetal 模板的处理屏幕我有一些过滤器值基于我的网格数据将被加载,我将修改价格字段,如上面提到的示例“新销售”我将修改的字段是未绑定的字段“销售”字段已绑定

所以在网格的行项目中,如果修改新销售,则需要比较销售和新销售,如果两个值相同,那么特别是对于 NewSales 字段,我需要显示绿色。

我在我的页面文件中尝试了下面的代码,但是当我调试时它没有调用这个 grid1_RowDataBound 事件

protected void Page_Load(object sender, EventArgs e)
    {
        //Create needed styles here
        Style style = new Style();
        style.Font.Bold = true;
        this.Page.Header.StyleSheet.CreateStyleRule(style, this, "." + "BoldText");

        Style style1 = new Style();
        style1.ForeColor = System.Drawing.Color.FromArgb(50, 180, 50);
        this.Page.Header.StyleSheet.CreateStyleRule(style1, this, "." + "GreenColor");
    }

    protected void grid1_RowDataBound(object sender, PX.Web.UI.PXGridRowEventArgs e)
    {
        // Take DataItem and convert it to your DAC object type
        // KWUpdateStylePricing is my DAC name
        KWUpdateStylePricing row = e.Row.DataItem as KWUpdateStylePricing;
        if (row != null && row.WholeSalePrice == row.NewWholeSalePrice)
        {
            e.Row.Style.CssClass = "GreenColor";
        }
    }

Aspx 页面网格属性

<px:PXGrid ID="grid1" runat="server" DataSourceID="ds" Style="z-index: 100; left: 0px; top: 0px; height: 385px;" Width="100%" NoteIndicator="false" FilesIndicator="false"
        BorderWidth="0px" OnRowDataBound="grid1_RowDataBound" SkinID="DetailsInTab" SyncPosition="True" StatusField="MyAvailability" RepaintColumns="true" Height="385px" TabIndex="7700" AllowPaging="true" AdjustPageSize="Auto" AllowSearch="true" AllowAutoHide="false">

提前致谢。

【问题讨论】:

    标签: acumatica acumatica-kb


    【解决方案1】:

    这取决于屏幕。如果你的屏幕是通用查询,你应该

    1. 转到通用查询设计器屏幕
    2. 打开所需的通用查询
    3. 打开结果网格选项卡
    4. 您可以在行样式或样式字段中定义行样式或单元格样式公式

    如果您的屏幕不是通用查询,则需要有代码将样式分配给相应 aspx.cs 文件中的单元格/行

    public partial class  Page_YourPage : PX.Web.UI.PXPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Create needed styles here
            Style style = new Style();
            style.Font.Bold = true;
            this.Page.Header.StyleSheet.CreateStyleRule(style, this, "." + "BoldText");
    
            Style style1 = new Style();
            style1.ForeColor = System.Drawing.Color.FromArgb(50, 180, 50);
            this.Page.Header.StyleSheet.CreateStyleRule(style1, this, "." + "GreenColor");
        }
    
        protected void grid1_RowDataBound(object sender, PX.Web.UI.PXGridRowEventArgs e)
        {
            // Take DataItem and convert it to your DAC object type
            GridObjectType row = e.Row.DataItem as GridObjectType;
            if (item != null && item.SomeField == true)
            {
                e.Row.Style.CssClass = "GreenColor";
            }
        }
    

    您需要在 aspx 文件中定义该事件,例如

    <px:PXGrid ID="grid1" runat="server" DataSourceID="ds" OnRowDataBound="grid1_RowDataBound" ... >
    

    您也可以查看这篇文章: http://asiablog.acumatica.com/2016/12/using-colors-in-acumatica.html

    【讨论】:

    【解决方案2】:

    我在为班级分配一行时遇到了麻烦。结果,我将行单元格分配给一个对象,然后执行我的逻辑。试试下面的代码,看看它是否有效。

    protected void grid_RowDataBound(object sender, PX.Web.UI.PXGridRowEventArgs e)
    {
        Object wholesaleprice = e.Row.Cells["WholeSalePrice"].Value;
        Object newwholesaleprice = e.Row.Cells["NewWholeSalePrice"].Value;
    
        if (wholesaleprice != null 
            && newwholesaleprice != null
            && ((decimal)wholesaleprice) == ((decimal)newwholesaleprice))
        {
            e.Row.Style.CssClass = "GreenColor";
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-17
      • 1970-01-01
      • 2021-08-18
      • 2018-02-12
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多