Im trying to define a Css style for a column in PXGrid.
<px:PXGrid ID="grid" runat="server" DataSourceID="ds" Width="100%"
TabIndex="100" SkinID="DetailsInTab" StatusField="Availability" SyncPosition="True" Height="473px" OnColumnDataBound="grid_rowBound">
protected void grid_rowBound(object sender, PX.Web.UI.PXGridRowEventArgs e)
{
Object value = e.Row.Cells["OrigQty"].Value;
if (value != null && ((Boolean)value) == false)
e.Row.Style.CssClass = "RedCol";
}
Is column styling possible using OnColumnDataBound?
You could create style dynamically as below in page code behind.
In below example, I have modified out-of-box EP503010
page.
protected void Page_Load(object sender, EventArgs e)
{
Style escalated = new Style();
escalated.ForeColor = System.Drawing.Color.Red;
this.Page.Header.StyleSheet.CreateStyleRule(escalated, this, ".CssEscalated");
Style rowStyle = new Style();
rowStyle.BackColor = System.Drawing.Color.Red;
this.Page.Header.StyleSheet.CreateStyleRule(rowStyle, this, ".CssRowStyle");
Style cellStyle = new Style();
cellStyle.BackColor = System.Drawing.Color.Aqua;
this.Page.Header.StyleSheet.CreateStyleRule(cellStyle, this, ".CssCellStyle");
Style highlightStyle = new Style();
highlightStyle.BackColor = System.Drawing.Color.Yellow;
this.Page.Header.StyleSheet.CreateStyleRule(highlightStyle, this, ".CssHighlightStyle");
}
And use that in OnRowDataBound
event handler of PXGrid
as below
protected void grid_RowDataBound(object sender, PX.Web.UI.PXGridRowEventArgs e)
{
EPApprovalProcess.EPOwned item = e.Row.DataItem as EPApprovalProcess.EPOwned;
if (item == null) return;
if (item.Escalated == true)
{
//For Row - change the Font to Red
e.Row.Style.CssClass = "CssEscalated";
}
else if (item.CuryTotalAmount.HasValue && item.CuryTotalAmount.Value > 10m)
{
//For Row - change the background to Red
e.Row.Style.CssClass = "CssRowStyle";
}
//For Specific Column - change the background to Aqua - Whole Column all row.
e.Row.Cells["Descr"].Style.CssClass = "CssCellStyle";
//Conditional a specific column cell
if (item.CuryTotalAmount.HasValue && item.CuryTotalAmount.Value > 10m)
{
e.Row.Cells["CuryTotalAmount"].Style.CssClass = "CssHighlightStyle";
}
}
You can refer out-of-box EP503010.aspx & EP503010.aspx.cs page files.