# Did anyone try to embed Datatables into Topic Body?

**URL:** <https://meta.discourse.org/t/did-anyone-try-to-embed-datatables-into-topic-body/129299>\
**Category:** Feature\
**Created:** [September 23, 2019, 12:59pm UTC](https://meta.discourse.org/t/did-anyone-try-to-embed-datatables-into-topic-body/129299 "2019-09-23T12:59:47Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)\
**Post date:** [June 27, 2021, 3:53pm UTC](https://meta.discourse.org/t/did-anyone-try-to-embed-datatables-into-topic-body/129299/11 "2021-06-27T15:53:23Z")

</div>

I have several tables that I’d like to include in my forum and your approach works perfectly. I’ve created this theme component initializer file:

```js
import { apiInitializer } from 'discourse/lib/api';
import loadScript from 'discourse/lib/load-script';

export default apiInitializer('0.11.1', (api) => {
  api.decorateCookedElement(
    (elem, helper) => {
      const dataTables = $('[data-wrap="dataTables"] table', elem);
      if (!dataTables.length) return;

      loadScript('https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js').then(
        () => {
          $.fn.dataTable.ext.errMode = 'throw';

          dataTables.dataTable({
            ajax: {
              url:
                'https://gist.githubusercontent.com/USERNAME/MY_GIST_ID/raw/data.json',
              dataSrc(data) {
                return data.map((x) => {
                  return {
                    id: x.my_id,
                    title: `${x.number} - ${x.title}`,
                  };
                });
              },
            },
            columns: [
              { data: 'id', title: 'My ID' }, 
              { data: 'title', title: 'My Title' }
            ],
            dom: 'Bfrt',
          });
        }
      );
    },
    { id: 'discourse-my-custom-data-tables', onlyStream: true }
  );
});

```

And I load the table in the post using this:

```plaintext
[wrap=dataTables]
<table></table>
[/wrap]

```

However, there are multiple things I’d like to customize for each table and I’m not sure how to go about it.

For example:

- I’d like to use a different Gist Id for each table. That should be easy enough by passing an attribute to the wrap and then accessing it with `elem.children[0].dataset.gist`:

- But what if I want multiple tables, each with different processing code in the `dataSrc` function or different `column` or `dom` parameters?

---

_[View the full topic](https://meta.discourse.org/t/did-anyone-try-to-embed-datatables-into-topic-body/129299)._
