This topic is locked

Dynamic Column Headers

8/19/2022 8:47:22 AM
ASPRunner.NET General questions
S
Stu1983 author

Hi, I have a report generated in SQL that covers a 3 year period with 1 column for each month.
To get this into ASPRunner.net I've called the column headers:
Y-1.01 for January last year,
Y-01.02 for February last year,
...
Y0.01 for January this year
...
Y+1.01 for January next year
...

This works fine and data can be view on a rolling 3 year table, however it would be nice to dynamically replace those labels with the actual year so this year Y-1 would be 2021, Y0 would be 2022 and Y+1 would be 2023 then next year everything would increase by 1.

A string replace formual would let me fix this but I'm not sure what event will let me catch this, I'm guessing the JavaScript OnLoad but not sure how to do this.

Another related issue the same data is being used in a line chart to plot the last 5 years, one line per year, these are labled as Y0, Y-1, Y-2... can these also be dynamically replaced with the actual year based on the current year?

Thanks
Stu

T
Tim 8/19/2022

Hi Stu,

I have a similar page with rolling quaterly numbers. For the column headers I insert a code snippet that uses today's date (Datetime.Now) and creates a date label in a format that works for us. Mine is futher complicated by needing to show our fiscal quarters (fiscal year starts July 1), but hopefully the general idea can help you. Here is the code I use in one of the snippets:

DateTime d = DateTime.Now;
//Get a current Quarter

int mth = DateTime.Now.Month;
if (mth <= 3)
{
XSession.Session["q0"]=("1Q"+d.Year % 50);
}
else if (mth > 3 && mth <= 6)
{
XSession.Session["q0"]=("2Q"+d.Year % 50);
}
else if (mth > 6 && mth <= 9)
{
XSession.Session["q0"]=("3Q"+d.Year % 50);
}
else if (mth > 9 && mth <= 12)
{
XSession.Session["q0"]=("4Q"+d.Year % 50);
}
return XSession.Session["q0"].ToString();

This will display 1Q22. And I have a different snippet for each column and do the math accordingly.

Hope this helps.
Tim

Sergey Kornilov admin 8/19/2022

In regards to dynamic field labels check Stroing field labels and visibility rules in the database article, it can help.

S
Stu1983 author 10/7/2022

Sorry only back to this again now.
Thanks for the help.

Hadn't thought of code snipets, good idea Tim that works perfect for display, though it doesn't appear when the resulting table is exported to excel.

Sergie, I'm struggling with your blog post, I'm following the C# sample at the bottom, lifted code exactly as it appears, just changed the 'settings' table to match my table name.

The 'visible' and 'readonly' flags are working but the 'label' and 'required' flags are being ignored.

Are the label and required lines of code still valid given the post was back in 2015?

GlobalVars.field_labels[t][CommonFunctions.mlang_getcurrentlang()][MVCFunctions.GoodFieldName(data["field"])]=data["label"];
if (data["required"]==1)
GlobalVars.tables_data[t][data["field"]]["EditFormats"]["edit"]["validateAs"]["basicValidate"][0]="IsRequired";

Thanks
Stu