Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional table column type creation, base on DataSource Field #5

Closed
molaie opened this issue Feb 21, 2019 · 8 comments
Closed

Conditional table column type creation, base on DataSource Field #5

molaie opened this issue Feb 21, 2019 · 8 comments

Comments

@molaie
Copy link

molaie commented Feb 21, 2019

creating table column type (or value) base on some condition on DatSource

And it is not a calculated field.
Say, for example in PdfReportSamples.Models, UserMonthCalendar, i have this new field:

 public class UserMonthCalendar {
    public int Id { set; get; }
    public string Name { set; get; }
    //new field added
    public bool Nodata { set; get; }
    public CalendarData MonthCalendarData { set; get; }
}

then i want to be able to do something like :

            columns.AddColumn(column => {
               if ( (bool)list.GetValueOf<UserMonthCalendar>(x => x.Nodata)) {
                    column.PropertyName<UserMonthCalendar>(x => x.Name);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(2);
                    column.Width(1);
                    column.HeaderCell("نام");
                } else {
			column.PropertyName<UserMonthCalendar>(x => x.MonthCalendarData);
			column.CellsHorizontalAlignment(HorizontalAlignment.Center);
			column.IsVisible(true);
			column.Order(3);
			column.Width(3);
			column.HeaderCell("تقويم ماهيانه");
			column.ColumnItemsTemplate(itemsTemplate =>
			{
				itemsTemplate.MonthCalendar(new CalendarAttributes
				{
					CalendarType = CalendarType.PersianCalendar,
					UseLongDayNamesOfWeek = true,
					Padding = 3,
					DescriptionHorizontalAlignment = HorizontalAlignment.Center,
					SplitRows = true,
					CellsCustomizer = info =>
					{
						if (info.Year == 1391 && info.Month == 1 && info.DayNumber == 1)
						{
							info.NumberCell.BackgroundColor = new BaseColor(System.Drawing.Color.LimeGreen.ToArgb());
							var phrase = info.NumberCell.Phrase;
							foreach (var chunk in phrase.Chunks)
								chunk.Font.Color = new BaseColor(System.Drawing.Color.Yellow.ToArgb());
						}
					}
				});
			});
                }

            });

but list is avaiable only in CalculatedField, and here the column is not a CalculatedField but a ConditionalColumn

Also, many thanks for your great work.

Environment

The in-use version: 2.9.2
@molaie
Copy link
Author

molaie commented Feb 21, 2019

i'm going to generate something like attached picture. obviously, this is Html, and i need to export it.
Be careful that row 1 has just a simple value from datasource, and second row, is a full table, with same instance of Datasource.

image

@VahidN
Copy link
Owner

VahidN commented Feb 21, 2019

Move your datasource

 var listOfRows = PersianMonthCalendarDataSource.CreateDataSource();

before

return new PdfReport().DocumentPreferences

Now you can access listOfRows everywhere.

@VahidN VahidN closed this as completed Feb 21, 2019
@molaie
Copy link
Author

molaie commented Feb 21, 2019

It is not about accessing listOfRows anywhere, i already pass datasource as input parameter to function.
I need to access current row index, to get some value of it, and then base on on some filed value, have 2 type of column rendering.
is there any way to do that?

@VahidN
Copy link
Owner

VahidN commented Feb 21, 2019

You can't do that. columns.AddColumn is a one time action. It's a definition of the structure of the table. you can't change it for the row n.

@molaie
Copy link
Author

molaie commented Feb 21, 2019

thanks for your patience, and how to create something like i want in picture that i have attached? (or any link to a sample on itextsharp).
it is really a nested table.

@VahidN
Copy link
Owner

VahidN commented Feb 21, 2019

Custom table cells are supported by PDFReport. Here you can return whatever you want as a pdfCell based on the attributes.RowData.TableRowData. It can be an HTML cell too. Also it can be defined as an inline custom cell provider.

@molaie
Copy link
Author

molaie commented Feb 21, 2019

And not related to main question, but how to hide table header row?
as in attached image(in second comment), i don't need to show any cell header.

@VahidN
Copy link
Owner

VahidN commented Feb 21, 2019

Set ShowHeaderRow to false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants