Add dynamic table column Follow
If you want to add extra table column to an automatic generated table, and you want to add fields to that table from another service, copy the following code snippet to the js file in AuraPlayer, and it would generate that extra table column with data.
function populateTable(tableOutputBody) {
if (tableOutputBody == null) {
return;
}
var columnsMetadata = getTableColumnsMetadata();
if (columnsMetadata == null) {
return;
}
clearAllTableRows();
//this line would add an extra table column header - called "Description"
$('#tableOutputHead tr').append('<th id="Description_0" name="Description" display-format="%s" style="font-weight: bolder; color:#696969"> Description</th>');
var lastIndex = getHighestIndex(columnsMetadata[0].id);
for (var i = 0; i <= lastIndex; i++) {
populateTableRow(tableOutputBody, columnsMetadata, i);
}
}
//the following function paints every row in the table
function populateTableRow(tableOutputBody, columnsMetadata, rowIndex) {
var rowCount = tableOutputBody.rows.length;
var row = tableOutputBody.insertRow(rowCount);
for (var i in columnsMetadata) {
var cellName = columnsMetadata[i].id;
var cellNameWithIdx = cellName.substr(0, getNameWoIndexLength(cellName)) + '_' + rowIndex;
var cellValue = formatTableValue(columnsMetadata[i].displayFormat, sessionStorage[cellNameWithIdx]);
var cell;
if (row.cells.length == 0) {
cell = document.createElement('td');
row.appendChild(cell);
} else {
cell = row.insertCell(-1);
}
cell.innerHTML = cellValue;
}
//the following rows would
var descIdCellName = columnsMetadata[0].id
var descId = descIdCellName.substr(0, getNameWoIndexLength(descIdCellName)) + '_' + rowIndex;
var descIdValue = formatTableValue(columnsMetadata[0].displayFormat, sessionStorage[descId]);
var desc = '';
//the following code would call a web service, and get the data, and set it in the table row
$.getJSON('http://<host>:<port>/ServiceManager/Macro/ExecMacro/<serviceName>', {key: value,key2:value2})
.then(function(res){
desc =res.Response.<serviceName>TableArray.<serviceName>ArrayItem[0].VI_CONCATENATED_DESCRIPTION;
cell = document.createElement('td');
row.appendChild(cell);
cell.innerHTML = desc;
})
}
Comments
0 comments
Please sign in to leave a comment.