Towards a generalized HTML table-generating scipt
I'm trying to generalize the table-generating script presented in https://help.zoho.com/portal/en/community/topic/html-views-18-2-2013 (which is quite useful as is).
My current version is as follows:
- htmlpage Table_script_test1()
displayname = "0Table script test"
content
<%{
Width = "1200";
Table_Caption = "WBS Info";
Col1_Header = "Activity";
Col2_Header = "Main Dependency";
//
Form_Name = "WBS";
Criteria = "ID != null";
Col1_Field = "Activity";
Col2_Field = "Main_Dependency";
//
tTop = "<table width=" + Width + " border='1' cellpadding='1' cellspacing='0'>";
tTop = ((tTop + "<caption class='zc-viewrowheader' style='font-size:14px; text-align:center'>") + Table_Caption) + "</caption>";
tTop = tTop + "<tbody><tr>";
//
tHeader = "";
tHeader = tHeader + "<td class='zc-viewrowheader' style='width:50%; text-align:center; font-weight:bold'>" + Col1_Header;
tHeader = tHeader + "<td class='zc-viewrowheader' style='width:50%; text-align:center; font-weight:bold'>" + Col2_Header;
tHeader = tHeader + "</td>";
//
tBody = "";
for each var in WBS
{
tBody = tBody + "<tr>";
tBody = ((tBody + "<td style='font-size:11px'>") + var.Activity) + "</td>";
tBody = ((tBody + "<td style='font-size:11px'>") + var.Main_Dependency) + "</td>";
tBody = tBody + "</tr>";
}
TABLE = tTop + tHeader + tBody + "</tbody></table>";%>
<%=TABLE%>
<%}%>
My challenge is as follows:
I would like to be able to use the [Form_Name] variable in the "for each" statement and the Col1_Field and Col2_Field variables in the <td> statement, so that, when reusing the script, I only had to edit the variable declarations in the top of the script.
The result should be something like this:
Form_Name = "WBS";
Criteria = "ID != null";
Col1_Field = "Activity";
Col2_Field = "Main_Dependency";
- ...
- ...
- ...
- for each var in <%=Form_Name%>
{
tBody = tBody + "<tr>";
tBody = ((tBody + "<td style='font-size:11px'>") + var. +<%=Col1_Field%>) + "</td>";
tBody = ((tBody + "<td style='font-size:11px'>") + var. +<%=Col2_Field%>) + "</td>";
tBody = tBody + "</tr>";
Is this viable? Any other way of achieving the generalization?
Thanks in advance,
Eriel Ramos-Pizarro