Display Tables with the JavaScript Library simple-datatables

We can use the JavaScript library simple-datatables to generate enhanced tables in HTML. In the example below, we create a table for the mtcars data:

::: {#mtcars-table}

mtcars

:::

Note we assigned an id to the table, and next we use the DataTables library to initialize the table and you will get an interactive table.

window.addEventListener('load', () => {
  new simpleDatatables.DataTable('#mtcars-table > table');
});

By comparison, below is an ordinary table:

mtcars


Try the knitr package in your browser

Any scripts or data that you put into this service are public.

knitr documentation built on April 4, 2025, 5:15 a.m.