1
votes

I have a requirement to set color for the grid column filed based on condition. For example: I have two fields in grid 1. Sales Price 2. New Sales I want to show Green color if Sales price and New Sales value is same else want to show red color if Sales price is higher than New Sales else want to show Yellow color if Sales price is lower than New Sales.

This is not a generic inquiry screen, this is like processing screen using FormDetal Template in header i have some filter values based on that my grid data will get load on that i will modify price fields as mention above example "New Sales" field i will modify and it is unbound field "Sales" field is bound

so in the line item of grid if modify new sales then need to compare sales and New sales if both value are same then particularly for the NewSales field i need to show Green color.

I tried below code in my page file, but when i debug it didn't call this grid1_RowDataBound event

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 page Grid properties

<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">

Thanks in advance.

2

2 Answers

0
votes

It depends on the screen. If your screen is a generic inquiry, you should

  1. go to the Generic Inquiry designer screen
  2. open the needed Generic Inquiry
  3. Open Results Grid tab
  4. You can define Row Style or cell style formula in Row Style or Style field

    Generic Inquiry design screen

If your screen is not a generic inquiry, you'll need to have code that assigns the style to the cell/row in the corresponding aspx.cs file

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";
        }
    }

In the aspx file you'll need to define that event, e.g.

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

You can also check this article: http://asiablog.acumatica.com/2016/12/using-colors-in-acumatica.html

0
votes

I've had trouble assigning a row to a class. As a result, I assign the row cell to an object and then perform my logic. Try something like the code below and see if it works.

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";
    }
}