I'm replacing a custom made table with PrimeNG's turbotable. I have some buttons I need to insert into the table that call special javascript functions I've written, but I'm stuck on how to insert the element into the table.
It displays as [object HTMLInputElement]
instead of as a button. I know the code that generates the button is good, because it worked great in the old table set up. I think the problem is the turbotable it turning it into text and I'm not sure how to make it stay HTML.
This is what's displayed.
Here's the turbotable
<p-table [columns]="resultsCols" [value]="results">
<ng-template pTemplate="caption">
Agencies Count {{results?.length}}
</ng-template>
<ng-template pTemplate="header">
<tr>
<th >Options</th>
<th [pSortableColumn]="'agency'" >Agency</th>
<th [pSortableColumn]="'department'" class="ui-p-2">Department</th>
<th [pSortableColumn]="'affiliateCount'" class="ui-p-4">Affiliate Count</th>
<th [pSortableColumn]="'basigdate'" class="ui-p-6">BA Sig Date</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-r>
<tr>
<td> {{r.btnEdit}}</td>
<td >{{r.agency}}</td>
<td class="ui-p-2">{{r.department}}</td>
<td class="ui-p-4">{{r.affiliateCount}}</td>
<td class="ui-p-6">{{r.basigdate}}</td>
</tr>
</ng-template>
</p-table>
Here's how I generate the button and populate the results array
var result = JSON.parse(xmlhttp.responseText);
for (var i = 0; i < result.length; i++) {
var inputEdit = document.createElement("input");
inputEdit.type = "button";
inputEdit.value = "Edit";
inputEdit.classList.add("btn-link");
inputEdit.onclick = (
function(i) {
return function() {
comp.setEditMode(i);
}
}
)(result[i].id);
var a = new agencySearchResult();
a.agency = result[i].name;
a.affiliateCount = result[i].affiliateCount;
a.basigdate = result[i].baSigDate;
a.department = result[i].department;
a.btnEdit = inputEdit;
comp.results.push(a);
}
Lastly, here's where the agencySearchResult
is defined in typescript
export class agencySearchResult {
constructor() {};
agency: string;
department: string;
affiliateCount: string;
basigdate: string;
btnEdit: HTMLInputElement;
}
I think the problem is the {{r.btnEdit}}
line in the HTML, but I included all the relevant stuff just in case.
So Internet, how do you insert a javascript generated HTML element into a turbotable ?