Question

Color grid rows.

  • 26 January 2024
  • 13 replies
  • 135 views

Userlevel 3
Badge

Hi All,

Need to know how to color grid rows based on grid value. 

Ex: if grid column value(x) equal to 1 then row color change to red else keeps default color.

Thanks

Bhagya


13 replies

Userlevel 7
Badge +5

The forum search returned a few hits:

and

https://stackoverflow.com/questions/70840294/how-can-i-get-row-colors-to-change-in-standard-grid-based-on-data-criteria

Userlevel 7
Badge +12

You will need to do a customisation in order to add it but fairly straight forward if you are comfortable with javascript. Here is a good article on it that should give you some pointer. If you search for javascript color Acumatica there is lots of info out there.

https://stackoverflow.com/questions/56582456/how-do-i-add-row-highlighting-to-a-customization-contained-within-a-base-acumati

Userlevel 7
Badge +17

Hi @bhagyat25 I have successfully completed the requirement around 2 years ago and provided the code in the below post. Hope this will help you.

 

 

Userlevel 3
Badge

Hi @bhagyat25 I have successfully completed the requirement around 2 years ago and provided the code in the below post. Hope this will help you.

 

 

Hi @Naveen Boga ,

I applied everything as you given but page load event is not triggering. 

protected virtual void Initialize()
        {
            Page page = HttpContext.Current?.Handler as PXPage;
            if (page != null)
            {
                page.Load += Page_Load;
            }
        }

Can you tell me any other things to do?

Thanks

Bhagya

Userlevel 7
Badge +17

Hi @bhagyat25  After initialize code methid, write a Page_Load event for the colors like below and verify.

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{

public override void Initialize()
{
Page page = HttpContext.Current?.Handler as PXPage;
if (page != null)
{
page.Load += Page_Load;
}
}

private void Page_Load(object sender, EventArgs e)
{
Page page = (Page)sender;
PXStyle rowStyle = new PXStyle();
rowStyle.BackColor = System.Drawing.Color.FromArgb(232, 252, 255);
page.Header.StyleSheet.CreateStyleRule(rowStyle, page, ".CssCurentRowStyle");

PXStyle rowStyleEditing = new PXStyle();
rowStyleEditing.BackColor = System.Drawing.Color.White;
page.Header.StyleSheet.CreateStyleRule(rowStyleEditing, page, ".CssCurentRowStyleEditing");

PXStyle cellStyleEditing = new PXStyle();
cellStyleEditing.BackColor = System.Drawing.Color.FromArgb(255, 255, 220);
page.Header.StyleSheet.CreateStyleRule(cellStyleEditing, page, ".CssCurentCellStyleEditing");

PXStyle cellStyleLastCost = new PXStyle();
cellStyleLastCost.BackColor = System.Drawing.Color.FromArgb(255, 217, 179);
page.Header.StyleSheet.CreateStyleRule(cellStyleLastCost, page, ".CssCurentCellStyleLastCost");

PXStyle cellStyleHeaderCurrent = new PXStyle();
cellStyleHeaderCurrent.BackColor = System.Drawing.Color.FromArgb(232, 252, 255);
page.Header.StyleSheet.CreateStyleRule(cellStyleHeaderCurrent, page, ".GridMain.Dash .GridRow.CssStyleHeaderCurrent");

PXStyle cellStyleHeaderPreview = new PXStyle();
cellStyleHeaderPreview.BackColor = System.Drawing.Color.FromArgb(255, 255, 220);
page.Header.StyleSheet.CreateStyleRule(cellStyleHeaderPreview, page, ".GridMain.Dash .GridRow.CssStyleHeaderPreview");


PX.Web.UI.PXGrid grdProfitBreakupByLine = (PX.Web.UI.PXGrid)ControlHelper.FindControl("grid", page);
if (grdProfitBreakupByLine != null)
{
grdProfitBreakupByLine.RowDataBound += (object grdsender, PXGridRowEventArgs erdb) =>
{
var data = erdb.Row.DataItem as PX.Objects.SO.SOLine;
if (data == null) { return; }

erdb.Row.Style.CssClass = data.CuryUnitPrice <= 0M ? "red20" : "black20";

};
}
}
}

 

Userlevel 3
Badge

Hi @bhagyat25  After initialize code methid, write a Page_Load event for the colors like below and verify.

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{

public override void Initialize()
{
Page page = HttpContext.Current?.Handler as PXPage;
if (page != null)
{
page.Load += Page_Load;
}
}

private void Page_Load(object sender, EventArgs e)
{
Page page = (Page)sender;
PXStyle rowStyle = new PXStyle();
rowStyle.BackColor = System.Drawing.Color.FromArgb(232, 252, 255);
page.Header.StyleSheet.CreateStyleRule(rowStyle, page, ".CssCurentRowStyle");

PXStyle rowStyleEditing = new PXStyle();
rowStyleEditing.BackColor = System.Drawing.Color.White;
page.Header.StyleSheet.CreateStyleRule(rowStyleEditing, page, ".CssCurentRowStyleEditing");

PXStyle cellStyleEditing = new PXStyle();
cellStyleEditing.BackColor = System.Drawing.Color.FromArgb(255, 255, 220);
page.Header.StyleSheet.CreateStyleRule(cellStyleEditing, page, ".CssCurentCellStyleEditing");

PXStyle cellStyleLastCost = new PXStyle();
cellStyleLastCost.BackColor = System.Drawing.Color.FromArgb(255, 217, 179);
page.Header.StyleSheet.CreateStyleRule(cellStyleLastCost, page, ".CssCurentCellStyleLastCost");

PXStyle cellStyleHeaderCurrent = new PXStyle();
cellStyleHeaderCurrent.BackColor = System.Drawing.Color.FromArgb(232, 252, 255);
page.Header.StyleSheet.CreateStyleRule(cellStyleHeaderCurrent, page, ".GridMain.Dash .GridRow.CssStyleHeaderCurrent");

PXStyle cellStyleHeaderPreview = new PXStyle();
cellStyleHeaderPreview.BackColor = System.Drawing.Color.FromArgb(255, 255, 220);
page.Header.StyleSheet.CreateStyleRule(cellStyleHeaderPreview, page, ".GridMain.Dash .GridRow.CssStyleHeaderPreview");


PX.Web.UI.PXGrid grdProfitBreakupByLine = (PX.Web.UI.PXGrid)ControlHelper.FindControl("grid", page);
if (grdProfitBreakupByLine != null)
{
grdProfitBreakupByLine.RowDataBound += (object grdsender, PXGridRowEventArgs erdb) =>
{
var data = erdb.Row.DataItem as PX.Objects.SO.SOLine;
if (data == null) { return; }

erdb.Row.Style.CssClass = data.CuryUnitPrice <= 0M ? "red20" : "black20";

};
}
}
}

 

Hi @Naveen Boga , Yes I did the same, But it is not working and to ensure that I put break points to both Page Load and Init methods, But none of them fired. Any clue?

Thanks

Bhagya

 

Userlevel 7
Badge +17

@bhagyat25  Have you chosen the right GRID ID from the .aspx page?

 

 

Userlevel 3
Badge

@bhagyat25  Have you chosen the right GRID ID from the .aspx page?

 

 

Hi @Naveen Boga, Yes, It’s same as the grid id, my main issue is why these events not triggered once I put break points and attach the process in the VS. Any clue?

 

Userlevel 7
Badge +17

@bhagyat25 Can you please share the customization package here?

 

Userlevel 3
Badge

@bhagyat25 Can you please share the customization package here?

 

Hi @Naveen Boga, Here is the package and screen id is RS403000. 

Userlevel 7
Badge +17

@bhagyat25  You have added to the DLL but I cannot access it. Can you let me know how to populate the records in the grid?

 

 

 

 

Userlevel 3
Badge

@bhagyat25  You have added to the DLL but I cannot access it. Can you let me know how to populate the records in the grid?

 

 

 

 

Hi @Naveen Boga , VS solution file and the table script. (BAccountID is from the BAccount Table)

Userlevel 7
Badge

Hi @bhagyat25 were you able to find a solution? Thank you!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved