​

CSV to web page with D3.js

This example dynamically creates a HTML table from a CSV file. Because of CORS, the CSV needs to be on the same server (site) as the page. If we update the CSV file in Contensis with new data, the web page updates next time it is loaded in the browser. 

In order to create the HTML table, we've used D3.js. The tutorial for this particular example can be found at www.tutorialguruji.com. This example is accessible as it generates headers.

Notes

  • This does not work in preview as the browser will block because of CORS.
  • The CSV can be placed anywhere on the page by using the <div id="csv-content"></div>.
  • In order to style the table, the JavaScript will append a class name of 'usr_TableDefault-container' to the div surrounding the table. 
  • Currently the CSS for the table is in the include file. If adopted, this would need to move to the main 400 CSS file. Suggest augmenting the current usr_default-table styles with the  '.usr_TableDefault-container table' addition.

Updating the CSV file

In Contensis, it's not possible to overwrite the CSV file in the same way as an image. Instead, a user should update the CSV in Excel, save as CSV and then open it again in Notepad and copy the contents. The CSV in Contensis is then edited by pasting over the data and publishing the CSV again in Contensis.

Page last reviewed: 29 December 2021