Jump to content

Can Number of Tables Rows Vary?


JoyceKeller

Recommended Posts

I don't understand. Do you mean the number of rows or the number of columns? The number of rows in a table is pretty much always variable, depending on much much data you have.

 

The number of columns is basically fixed for the entire table. However, you can span (merge) multiple rows and columns with the "hstraddle" and "vstraddle" attributes of the <cell> tag; see "Example of Building Advanced Tables" in the Tags Reference Guide. You can also always start a new table with a different number of columns.

Link to comment
Share on other sites

Thanks for your response. I meant number of rows.

 

Here is the User Scenario:

 

User will be selecting widget part numbers available from dropdowns to auto-populate a grid. Part numbers populate column 1. User is limited to a max of 20 rows. The first 12 part numbers are fixed. The next 3 are required, and the last 5 are optional. The part numbers selected determine how the rest of the grid will automatically fill (I got this part). The grid is 7 columns wide (fixed).

 

I am sure the problem lies in how I have written adding rows to the table. If the User does not choose the 5 optional part numbers, I am left with unwanted blank rows and lines.

 

//WidgetTable

var table = new FPTable;

table.AddColumns(8800, 7200, 7200, 8400, 8400, 8400, 6400);

table.AddRows(21); //Adds the number of rows to the table. Row 1 is the header.

 

for(a=0;a<=20;a++)

{

for(b=0;b<7;b++)

{

table.Rows[a].Cells.SetBorders("Thin", "Gray", "Top", "Bottom");

table.Rows[a].Cells.Margins = new FPTableMargins;

table.Rows[a].Cells.Margins.Top = 60;

table.Rows[a].Cells.Margins.Bottom = 40;

table.Rows[a].Cells.Margins.Left = 600;

table.Rows[a].Cells.Margins.Right = 600;

}

}

table.Rows[0].Type = "Header";

for(i=0;i<=20;i++)

table.Rows.Cells[0].Bold = "On";

 

table.Rows[0].Cells[0].Content = "WIDGET #";

table.Rows[0].Cells[1].Content = "SALE PRICE";

table.Rows[0].Cells[2].Content = "xChange1";

table.Rows[0].Cells[3].Content = "xChange2";

table.Rows[0].Cells[4].Content = "xChange3";

table.Rows[0].Cells[5].Content = "xChange4";

table.Rows[0].Cells[6].Content = "xChange5";

 

table.Rows[1].Cells[0].Content = "1243";

table.Rows[1].Cells[1].Content = "$2.64";

table.Rows[1].Cells[2].Content = "BT259";

table.Rows[1].Cells[3].Content = "P55-0020";

table.Rows[1].Cells[4].Content = "LF678";

table.Rows[1].Cells[5].Content = "T19044T";

table.Rows[1].Cells[6].Content = "3I-1089";

 

table.Rows[2].Cells[0].Content = "1748";

table.Rows[2].Cells[1].Content = "$18.21";

table.Rows[2].Cells[2].Content = "BD103";

table.Rows[2].Cells[3].Content = "P55-3000";

table.Rows[2].Cells[4].Content = "LF3000";

table.Rows[2].Cells[5].Content = "RE44647";

table.Rows[2].Cells[6].Content = "3I-1265";

 

table.Rows[3].Cells[0].Content = "1970";

table.Rows[3].Cells[1].Content = "$8.98";

table.Rows[3].Cells[2].Content = "B95";

table.Rows[3].Cells[3].Content = "P55-0911";

table.Rows[3].Cells[4].Content = "LF3353";

table.Rows[3].Cells[5].Content = "N/A";

table.Rows[3].Cells[6].Content = "3I-1201";

 

table.Rows[4].Cells[0].Content = "1971";

table.Rows[4].Cells[1].Content = "$8.37";

table.Rows[4].Cells[2].Content = "B495";

table.Rows[4].Cells[3].Content = "P55-2100";

table.Rows[4].Cells[4].Content = "LF3617J";

table.Rows[4].Cells[5].Content = "N/A";

table.Rows[4].Cells[6].Content = "N/A";

 

table.Rows[5].Cells[0].Content = "7243";

table.Rows[5].Cells[1].Content = "$6.01";

table.Rows[5].Cells[2].Content = "B7125";

table.Rows[5].Cells[3].Content = "P55-1352";

table.Rows[5].Cells[4].Content = "LF3703";

table.Rows[5].Cells[5].Content = "RE59754";

table.Rows[5].Cells[6].Content = "N/A";

 

table.Rows[6].Cells[0].Content = "3109";

table.Rows[6].Cells[1].Content = "$3.35";

table.Rows[6].Cells[2].Content = "BF957";

table.Rows[6].Cells[3].Content = "P55-0105";

table.Rows[6].Cells[4].Content = "FF105";

table.Rows[6].Cells[5].Content = "N/A";

table.Rows[6].Cells[6].Content = "3I-0750";

 

table.Rows[7].Cells[0].Content = "3358";

table.Rows[7].Cells[1].Content = "$3.60";

table.Rows[7].Cells[2].Content = "BF988";

table.Rows[7].Cells[3].Content = "P55-0272";

table.Rows[7].Cells[4].Content = "FF231";

table.Rows[7].Cells[5].Content = "N/A";

table.Rows[7].Cells[6].Content = "3I-1179";

 

table.Rows[8].Cells[0].Content = "3370";

table.Rows[8].Cells[1].Content = "$5.98";

table.Rows[8].Cells[2].Content = "BF909";

table.Rows[8].Cells[3].Content = "P55-1130";

table.Rows[8].Cells[4].Content = "FF203";

table.Rows[8].Cells[5].Content = "AR50041";

table.Rows[8].Cells[6].Content = "3I-1233";

 

table.Rows[9].Cells[0].Content = "3405";

table.Rows[9].Cells[1].Content = "$6.73";

table.Rows[9].Cells[2].Content = "BF1249";

table.Rows[9].Cells[3].Content = "P55-0691";

table.Rows[9].Cells[4].Content = "FF105D";

table.Rows[9].Cells[5].Content = "RE42050";

table.Rows[9].Cells[6].Content = "3I-1144";

 

table.Rows[10].Cells[0].Content = "3472";

table.Rows[10].Cells[1].Content = "$5.73";

table.Rows[10].Cells[2].Content = "BF1221";

table.Rows[10].Cells[3].Content = "P55-0248";

table.Rows[10].Cells[4].Content = "FF215";

table.Rows[10].Cells[5].Content = "N/A";

table.Rows[10].Cells[6].Content = "3I-1196";

 

table.Rows[11].Cells[0].Content = "3674";

table.Rows[11].Cells[1].Content = "$7.28";

table.Rows[11].Cells[2].Content = "BF7587";

table.Rows[11].Cells[3].Content = "P55-1311";

table.Rows[11].Cells[4].Content = "FF5319";

table.Rows[11].Cells[5].Content = "N/A";

table.Rows[11].Cells[6].Content = "1R-0749";

 

table.Rows[12].Cells[0].Content = "4071";

table.Rows[12].Cells[1].Content = "$5.29";

table.Rows[12].Cells[2].Content = "BW5137";

table.Rows[12].Cells[3].Content = "P55-4018";

table.Rows[12].Cells[4].Content = "WF2051";

table.Rows[12].Cells[5].Content = "AR87114";

table.Rows[12].Cells[6].Content = "3I-1288";

 

table.Rows[13].Cells[0].Content = Field("Widget01");

table.Rows[13].Cells[1].Content = Rule("CalculateSalePrice01");

table.Rows[13].Cells[2].Content = Rule("Widget01xChange1");

table.Rows[13].Cells[3].Content = Rule("Widget01xChange2");

table.Rows[13].Cells[4].Content = Rule("Widget01xChange3");

table.Rows[13].Cells[5].Content = Rule("Widget01xChange4");

table.Rows[13].Cells[6].Content = Rule("Widget01xChange5");

 

table.Rows[14].Cells[0].Content = Field("Widget02");

table.Rows[14].Cells[1].Content = Rule("CalculateSalePrice02");

table.Rows[14].Cells[2].Content = Rule("Widget02xChange1");

table.Rows[14].Cells[3].Content = Rule("Widget02xChange2");

table.Rows[14].Cells[4].Content = Rule("Widget02xChange3");

table.Rows[14].Cells[5].Content = Rule("Widget02xChange4");

table.Rows[14].Cells[6].Content = Rule("Widget02xChange5");

 

table.Rows[15].Cells[0].Content = Field("Widget03");

table.Rows[15].Cells[1].Content = Rule("CalculateSalePrice03");

table.Rows[15].Cells[2].Content = Rule("Widget03xChange1");

table.Rows[15].Cells[3].Content = Rule("Widget03xChange2");

table.Rows[15].Cells[4].Content = Rule("Widget03xChange3");

table.Rows[15].Cells[5].Content = Rule("Widget03xChange4");

table.Rows[15].Cells[6].Content = Rule("Widget03xChange5");

 

table.Rows[16].Cells[0].Content = Field("Widget04");

table.Rows[16].Cells[1].Content = Rule("CalculateSalePrice04");

table.Rows[16].Cells[2].Content = Rule("Widget04xChange1");

table.Rows[16].Cells[3].Content = Rule("Widget04xChange2");

table.Rows[16].Cells[4].Content = Rule("Widget04xChange3");

table.Rows[16].Cells[5].Content = Rule("Widget04xChange4");

table.Rows[16].Cells[6].Content = Rule("Widget04xChange5");

 

table.Rows[17].Cells[0].Content = Field("Widget05");

table.Rows[17].Cells[1].Content = Rule("CalculateSalePrice05");

table.Rows[17].Cells[2].Content = Rule("Widget05xChange1");

table.Rows[17].Cells[3].Content = Rule("Widget05xChange2");

table.Rows[17].Cells[4].Content = Rule("Widget05xChange3");

table.Rows[17].Cells[5].Content = Rule("Widget05xChange4");

table.Rows[17].Cells[6].Content = Rule("Widget05xChange5");

 

table.Rows[18].Cells[0].Content = Field("Widget06");

table.Rows[18].Cells[1].Content = Rule("CalculateSalePrice06");

table.Rows[18].Cells[2].Content = Rule("Widget06xChange1");

table.Rows[18].Cells[3].Content = Rule("Widget06xChange2");

table.Rows[18].Cells[4].Content = Rule("Widget06xChange3");

table.Rows[18].Cells[5].Content = Rule("Widget06xChange4");

table.Rows[18].Cells[6].Content = Rule("Widget06xChange5");

 

table.Rows[19].Cells[0].Content = Field("Widget07");

table.Rows[19].Cells[1].Content = Rule("CalculateSalePrice07");

table.Rows[19].Cells[2].Content = Rule("Widget07xChange1");

table.Rows[19].Cells[3].Content = Rule("Widget07xChange2");

table.Rows[19].Cells[4].Content = Rule("Widget07xChange3");

table.Rows[19].Cells[5].Content = Rule("Widget07xChange4");

table.Rows[19].Cells[6].Content = Rule("Widget07xChange5");

 

table.Rows[20].Cells[0].Content = Field("Widget08");

table.Rows[20].Cells[1].Content = Rule("CalculateSalePrice08");

table.Rows[20].Cells[2].Content = Rule("Widget08xChange1");

table.Rows[20].Cells[3].Content = Rule("Widget08xChange2");

table.Rows[20].Cells[4].Content = Rule("Widget08xChange3");

table.Rows[20].Cells[5].Content = Rule("Widget08xChange4");

table.Rows[20].Cells[6].Content = Rule("Widget08xChange5");

 

table = table.MakeTags();

return table

Link to comment
Share on other sites

Okay, I see; you're using the new table API. Instead of hard-coding a fixed number of rows at the beginning, what you want to do is conditionally add rows as you go, and then apply the formatting to the rows at the end. I'm assuming that if the optional part numbers aren't selected, then the values of fields "Widget05" et al are empty. Try this:

FPTable.prototype.NewRow = function()
{
   table.AddRows(1);
   return table.Rows[table.Rows.length-1];
}

//WidgetTable
var table = new FPTable;
table.AddColumns(8800, 7200, 7200, 8400, 8400, 8400, 6400);

// Add rows as we go...
var row = null; // FPTableRow

row = table.NewRow();
row.Type = "Header";
row.Cells[0].Content = "WIDGET #";
row.Cells[1].Content = "SALE PRICE";
row.Cells[2].Content = "xChange1";
row.Cells[3].Content = "xChange2";
row.Cells[4].Content = "xChange3";
row.Cells[5].Content = "xChange4";
row.Cells[6].Content = "xChange5";

// Fixed row values:
row = table.NewRow();
row.Cells[0].Content = "1243";
row.Cells[1].Content = "$2.64";
row.Cells[2].Content = "BT259";
row.Cells[3].Content = "P55-0020";
row.Cells[4].Content = "LF678";
row.Cells[5].Content = "T19044T";
row.Cells[6].Content = "3I-1089";

row = table.NewRow();
row.Cells[0].Content = "1748";
row.Cells[1].Content = "$18.21";
row.Cells[2].Content = "BD103";
row.Cells[3].Content = "P55-3000";
row.Cells[4].Content = "LF3000";
row.Cells[5].Content = "RE44647";
row.Cells[6].Content = "3I-1265";

row = table.NewRow();
row.Cells[0].Content = "1970";
row.Cells[1].Content = "$8.98";
row.Cells[2].Content = "B95";
row.Cells[3].Content = "P55-0911";
row.Cells[4].Content = "LF3353";
row.Cells[5].Content = "N/A";
row.Cells[6].Content = "3I-1201";

row = table.NewRow();
row.Cells[0].Content = "1971";
row.Cells[1].Content = "$8.37";
row.Cells[2].Content = "B495";
row.Cells[3].Content = "P55-2100";
row.Cells[4].Content = "LF3617J";
row.Cells[5].Content = "N/A";
row.Cells[6].Content = "N/A";

row = table.NewRow();
row.Cells[0].Content = "7243";
row.Cells[1].Content = "$6.01";
row.Cells[2].Content = "B7125";
row.Cells[3].Content = "P55-1352";
row.Cells[4].Content = "LF3703";
row.Cells[5].Content = "RE59754";
row.Cells[6].Content = "N/A";

row = table.NewRow();
row.Cells[0].Content = "3109";
row.Cells[1].Content = "$3.35";
row.Cells[2].Content = "BF957";
row.Cells[3].Content = "P55-0105";
row.Cells[4].Content = "FF105";
row.Cells[5].Content = "N/A";
row.Cells[6].Content = "3I-0750";

row = table.NewRow();
row.Cells[0].Content = "3358";
row.Cells[1].Content = "$3.60";
row.Cells[2].Content = "BF988";
row.Cells[3].Content = "P55-0272";
row.Cells[4].Content = "FF231";
row.Cells[5].Content = "N/A";
row.Cells[6].Content = "3I-1179";

row = table.NewRow();
row.Cells[0].Content = "3370";
row.Cells[1].Content = "$5.98";
row.Cells[2].Content = "BF909";
row.Cells[3].Content = "P55-1130";
row.Cells[4].Content = "FF203";
row.Cells[5].Content = "AR50041";
row.Cells[6].Content = "3I-1233";

row = table.NewRow();
row.Cells[0].Content = "3405";
row.Cells[1].Content = "$6.73";
row.Cells[2].Content = "BF1249";
row.Cells[3].Content = "P55-0691";
row.Cells[4].Content = "FF105D";
row.Cells[5].Content = "RE42050";
row.Cells[6].Content = "3I-1144";

row = table.NewRow();
row.Cells[0].Content = "3472";
row.Cells[1].Content = "$5.73";
row.Cells[2].Content = "BF1221";
row.Cells[3].Content = "P55-0248";
row.Cells[4].Content = "FF215";
row.Cells[5].Content = "N/A";
row.Cells[6].Content = "3I-1196";

row = table.NewRow();
row.Cells[0].Content = "3674";
row.Cells[1].Content = "$7.28";
row.Cells[2].Content = "BF7587";
row.Cells[3].Content = "P55-1311";
row.Cells[4].Content = "FF5319";
row.Cells[5].Content = "N/A";
row.Cells[6].Content = "1R-0749";

row = table.NewRow();
row.Cells[0].Content = "4071";
row.Cells[1].Content = "$5.29";
row.Cells[2].Content = "BW5137";
row.Cells[3].Content = "P55-4018";
row.Cells[4].Content = "WF2051";
row.Cells[5].Content = "AR87114";
row.Cells[6].Content = "3I-1288";

// Widget rows; some are optional.
for (var widgetNum = 1; widgetNum <= 8; widgetNum++)
{
   var widgetNumPadded = FormatNumber("00", widgetNum);
   var FieldVal = "";
   try { FieldVal = Field("Widget" + widgetNumPadded); } catch (e) {}
   if (FieldVal)
   {
       row = table.NewRow();
       row.Cells[0].Content = FieldVal;
       row.Cells[1].Content = Rule("CalculateSalePrice" + widgetNumPadded);
       for (var c = 1; c <= 5; c++)
           row.Cells[c+1].Content = Rule("Widget" + widgetNumPadded + "xChange" + c);
   }
}

// Apply formatting to all the rows.
for (var a = 0; a < table.Rows.length; a++)
{
   table.Rows[a].Cells[0].Bold = "On";

   for (var b = 0; b < table.Columns.length; b++)
   {
       table.Rows[a].Cells[b].SetBorders("Thin", "Gray", "Top", "Bottom");
       table.Rows[a].Cells[b].Margins = new FPTableMargins;
       table.Rows[a].Cells[b].Margins.Top = 60;
       table.Rows[a].Cells[b].Margins.Bottom = 40;
       table.Rows[a].Cells[b].Margins.Left = 600;
       table.Rows[a].Cells[b].Margins.Right = 600;
   }
}

return table.MakeTags();

You can see that I've also reduced some of the repetitive code with for loops. (I'm a developer; I can't resist.)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...