This project has moved. For the latest updates, please go here.

Suppose we want to display the list of the personnel in a year. In this report each month cell with month=7 should be displayed with a different color. To achieve this goal we can use the template.ConditionalFormatFormula method:

                 columns.AddColumn(column =>
                 {
                     column.PropertyName("Month");
                     column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                     column.IsVisible(true);
                     column.Order(2);
                     column.Width(2);
                     column.HeaderCell("Month");
                     column.ColumnItemsTemplate(template =>
                     {
                         template.TextBlock();
                         template.ConditionalFormatFormula(list =>
                         {
                             var cellValue = int.Parse(list.GetSafeStringValueOf("Month", nullValue: "0"));
                             if (cellValue == 7)
                             {
                                 return new CellBasicProperties
                                 {
                                     PdfFontStyle = DocumentFontStyle.Bold | DocumentFontStyle.Underline,
                                     FontColor = new BaseColor(System.Drawing.Color.Brown),
                                     BackgroundColor = new BaseColor(System.Drawing.Color.Yellow)
                                 };
                             }
                             return new CellBasicProperties { PdfFontStyle = DocumentFontStyle.Normal };
                         });
                     });
                 });

template.ConditionalFormatFormula is a callback method which gives us the list of the current row's data. Now based on the value of the month (or other properties) we can return the "new CellBasicProperties" with different font color, style, etc.

You can find the related sample here: (+)

Last edited Nov 5, 2012 at 6:55 PM by VahidN, version 4

Comments

No comments yet.