You cannot use a ListView like this. The ListView control adds a whole stack of additional elements to do its job, which causes problems with the table.
The answer is to work directly with the WinJS.Binding.Template control and use it to insert rows into your table element. Here is the HTML you'll need for the template:
<table > <tbody id="myTemplate" data-win-control="WinJS.Binding.Template"> <tr > <td data-win-bind="innerText: label"></td> <td data-win-bind="innerText: value"></td> <td></td> </tr> </tbody> </table>
You need to put the full table and tbody in the markup, so that the browser does not get upset, find the untethered tr element or insert the tbody element itself. The external element of the template is discarded, so only the tr tag will be created from the template when using it.
Here is the markup for the table into which the generated elements will be inserted - this is what you had, except that I added the id attribute so that I can find the element to insert content from Javascript:
<table> <thead> <tr> <th>col1</th> <th>col2</th> <th>col2</th> </tr> </thead> <tbody id="myTableBody"> </tbody> </table>
Finally, here is the code:
WinJS.UI.processAll().then(function () { var tableBody = document.getElementById("myTableBody"); var template = document.getElementById("myTemplate").winControl; topContent.forEach(function (item) { template.render(item, tableBody); }); });
You must ensure that the Promise returned by WinJS.UI.processAll is executed before using the template. Calling the render method for each element that you want to process is the data element that you need to pass to the template to bind the data, and the DOM element to insert the generated elements into.
source share