Seal Report Forum
»
Report Edition
»
Reports
»
Dynamically change data table column titles
Rank: Newbie
Groups: Registered
Joined: 2/14/2019(UTC) Posts: 5 Location: Harpenden Was thanked: 1 time(s) in 1 post(s)
|
I am trying to find a way to change the Name of a column in the reports table based on values in the database. For example I have two db fields (Cat1 & Cat2) that in one case could be used to hold Country & Town and in another Name & Surname or anything else.
I had a play with the custom enumerated list but I guess this is for the values and not the title.
Is there a way of finding what are the methods and properties of the objects in the razor scripts? I believe the solution to my problem is in model.Elements but I have no way of knowing what is available to try.
Congratulations on the great product!
Thank you
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
As a general rule: try to do it in SQL, then display the result in SR. Once you have a SELECT SQL statement that works, it is easy to display it in SR.
So, for me you have to do this in SQL first, as the result table will have only 1 column title, you have to present a final table to SR having either a column named 'Col1' or 'Col2', it should be easy to do this in SQL.
If you want to do it in SR with C#, you have 2 options: Modify the result table in the 'Final Script' of you model, check the sample '54-Final Script - Change result table'. Use a custom the template of the 'Data Table' view and change the HTML generated.
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 2/14/2019(UTC) Posts: 5 Location: Harpenden Was thanked: 1 time(s) in 1 post(s)
|
Hi epf, Thank for your reply. I have chosen to take the option to modify the result table in the Final script. I managed to modify the headers with some text (thanks to 54-Final Script) but I don't seem to be able to pull the values from the restriction and rename accordingly.
I have a restriction that has the Enum Col1: Country, Col2: Town. My column is named "Col1" and my goal is to rename it to "Country" based on the restriction. My two questions are: 1. How can I access all the values from an Enum restriction and not only the selected ones which I know are in EnumValues? 2. How can I access the Identifier (Col1) and the Value (Country) pair from an Enum restriction?
Thanks for all your help
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
Yes we have to publish the object model online, Here is how to browse the enum definition of a restriction: Code:
//Display value from ID
string enumDisplayVal = restriction.GetEnumDisplayValue(restriction.EnumValues[0]);
//List enum values
MetaEnum enumDef = restriction.EnumRE;
foreach (MetaEV enumValue in enumDef.Values) {
string enumId = enumValue.Id;
string enumVal = enumValue.Val;
string enumValRE = enumValue.ValR; //.Css, .Class
}
Edited by user Wednesday, July 3, 2019 7:22:31 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 2/14/2019(UTC) Posts: 5 Location: Harpenden Was thanked: 1 time(s) in 1 post(s)
|
Well that did the Job! It works thanks to your help epf. Thank you very much. I am including my (mostly yours) code in case someone wants to use it. Code:
ReportRestriction CatRestriction = model.GetRestrictionByName("Analysis Fields");
foreach (ResultPage page in model.Pages)
{
for (int col = 0; col < page.DataTable.Lines[0].Length; col++)
{
page.DataTable.Lines[0][col].Value = CatRestriction.GetEnumDisplayValue((string)page.DataTable.Lines[0][col].Value);
}
}
|
1 user thanked ptsepeli for this useful post.
|
|
|
Seal Report Forum
»
Report Edition
»
Reports
»
Dynamically change data table column titles
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.