I am trying to build a table dynamically by passing an array of 23 objects, and an array containing the number of columns per row. (I think this part is what I do not have right). Each row has different number of columns, and the largest number of columns is 3.
I am not sure my code is doing what I need it to do, that is it is not calculating which row and cell should write the data.
The output should be like (labels and values are going inside the same cell) desired output of table:
The array containing the number of columns per row:
columns: Array[19]
0: 2
1: 1
2: 3
3: 2
4: 2
5: 1
6: 1
7: 1
8: 1
9: 1
10: 1
11: 1
12: 1
13: 1
14: 1
15: 1
16: 1
17: 1
18: 1
length: 19
The array of objects and the contained data have this format:
recordSets: Array[1]
0: Object
records:
0: Object
html: "<input id="txtCompanyName" name="CompanyName" value="Company" />"
info: "Bank"
label: "Profile:"
name: "Name"
type: "HtmlInputText"
1: Object
html: "<input id="txtTier" name="Tier" value="Tier 1" />"
info: "Tier 1"
label: "Tier:"
name: "Tier"
type: "HtmlInputText"
2: Object
html: "<textarea id="taCompanyDescription" name="CompanyDescription" value="Our goal is to make life simple"></textarea>"
info: "Our goal is to make life simple"
label: "Description:"
name: "CompanyDescription"
type: "HtmlTextArea"
3: Object
html: "<input id="txtMeetingDate" name="MeetingDate" class="datepicker_ref popup" ng-model="MeetingDate" value="2015-12-27T00:00:00" />"
info: "2015-12-27T00:00:00"
label: "Date:"
name: "MeetingDate"
type: "HtmlInputText"
4: Object
html: "<input id="txtMeetingTime" name="MeetingTime" value="01:00:00" ng-model="MeetingTime" />"
info: "01:00:00"
label: "Time:"
name: "MeetingTime"
type: "HtmlInputText"
5: Object
html: "<input id="txtLocation" name="Location" value="City View" />"
info: "City View"
label: "Location:"
name: "MeetingLocation"
type: "HtmlInputText"
6: Object
html: "<input id="txtAtendeeName" name="AtendeeName" value="Name" />"
info: "Name"
label: "Attendee Name"
name: "AttendeeName"
type: "HtmlInputText"
7: Object
html: "<input id="txtAtendeeRole" name="AtendeeName" value="Role" />"
info: "Role"
label: "Attendee Role"
name: "AttendeeRole"
type: "HtmlInputText"
8: Object
html: "<select name="ABAttendeeName" id="ddlABAttendeeName"></select>"
info: "Luke Fuss"
label: "AB Attendee Name"
name: "ABAttendeeName"
type: "HtmlSelect"
9: Object
html: "<select name="ABAttendeeRole" id="ddlABAttendeeRole"></select>"
info: "New Role"
label: "AB Attendee Role"
name: "ABAttendeeRole"
type: "HtmlSelect"
10: Object
html: "<input id="txtSection1Question1" name="Section1Question1" value="Goal" />"
info: "Goal"
label: "1) Primary goal?"
name: "Section1Question1"
type: "HtmlInputText"
11: Object
html: "<input id="txtSection1Question2" name="Section1Question2" value="Update" />"
info: "Update"
label: "2) Updated financials?"
name: "Section1Question2"
type: "HtmlInputText"
12: Object
html: "<input id="txtSection1Question3" name="Section1Question3" value="Other Docs" />"
info: "Other Docs"
label: "3) Other documents to bring"
name: "Section1Question3"
type: "HtmlInputText"
13: Object
html: "<input id="txtSection1Question4" name="Section1Question4" value="Discuss" />"
info: "Discuss"
label: "4) Specific products to discuss:"
name: "Section1Question4"
type: "HtmlInputText"
14: Object
html: "<input id="txtSection1Question5" name="Section1Question5" value="Key/ New Deal" />"
info: "Key/ New Deal"
label: "5) Key competitor(s) if a renewal or if new deal:"
name: "Section1Question5"
type: "HtmlInputText"
15: Object
html: "<input id="txtSection2Question1" name="Section2Question1" value="Top 3" />"
info: "Top 3"
label: "What are the top 3 initiatives for the company over the next 6-24 months?"
name: "Section2Question1"
type: "HtmlInputText"
16: Object
html: "<input id="txtSection2Question2" name="Section2Question2" value="Trends" />"
info: "Trends"
label: "What trends are affecting your business? What keeps you up at night?"
name: "Section2Question2"
type: "HtmlInputText"
17: Object
html: "<input id="txtSection2Question3" name="Section2Question3" value="Relationship" />"
info: "Relationship"
label: "What is important to company in a banking relationship?"
name: "Section2Question3"
type: "HtmlInputText"
18: Object
html: "<input id="txtSection2Question4" name="Section2Question4" value="Management Roles" />"
info: "Management Roles"
label: "What are key roles and structure of the management team?"
name: "Section2Question4"
type: "HtmlInputText"
19: Object
html: "<input id="txtSection2Question5" name="Section2Question5" value="Purchasing Plans" />"
info: "Purchasing Plans"
label: "Does the company have plans to purchase real estate or equipment in the next two years?"
name: "Section2Question5"
type: "HtmlInputText"
20: Object
html: "<input id="txtSection2Question6" name="Section2Question6" value="Staff Changed" />"
info: "Staff Changed"
label: "Any changes in staffing planned?"
name: "Section2Question6"
type: "HtmlInputText"
21: Object
html: "<input id="txtSection2Question7" name="Section2Question7" value="Not Bank" />"
info: "Not Bank"
label: "Any changes with Advisor or other non AB products?"
name: "Section2Question7"
type: "HtmlInputText"
22: Object
html: "<input id="txtSection2Question8" name="Section2Question8" value="Other" />"
info: "Other"
label: "Other"
name: "Section2Question8"
type: "HtmlInputText"
The function I am working with:
function DynamicTableBuilder(columns, data) {
if (!columns || !data) {
return;
}
var table = '<table><tbody><tr>';
var max = Math.max.apply(Math, columns);
for (var index = 0, length = data.length; index < length; index++) {
for (var j = 0, l = columns.length; j < l; j++) {
if (columns[j] === max) {
table += '<td>';
}
else {
table += '<td colspan="' + (max / columns[j]) + '">';
}
table += data[index].records[j].label + ': ' + data[index].records[j].info + '</td>'
}
}
table += '</tr></tbody></table>';
return table;
};
records[1]) just one element of array of colspans (columns[19])? as in multidimensional array?