Skip to content
Advertisement

Tabulator: load data from a JSON file

I want Tabulator to automatically load data from a JSON file.
I have made it work with a button.
I have read the q & a here
Load table data from text file
I have also read the documentation here.
http://tabulator.info/docs/4.4/data#array-initial
(By the way, I was expecting the ajaxURL documentation to show a URL ending with a FILE name rather than “/now”… something like $("#div1").load("demo_test.txt"); )

I’m not a professional developer so please be gentle with me.

Here is the content of the JSON file (called “test_Array.txt” and in the same directory as the HTML).

JavaScript

It passes validation at https://jsonlint.com/

Here is the HTML

JavaScript

What am I doing wrong?
Thank you.

Advertisement

Answer

To start off I would say you have posted a link to the v4.4 documentation, but using version 5.1 of Tabulator. It is defo worth reading the correct docs to get started 🙂

Following on from that the issue that you are experiencing is because as of version 5.0 Tabulator now has an async start up process that means you cant just call setData straight after instantiating the table, you must wait for the tableBuilt event:

JavaScript

More importantly if you are just loading data straight from the file then there is no need to set data after the table has been built, you can use the ajaxURL setup option to load the data into the table while it is being built:

JavaScript

As a complete aside if the text file just contains JSON data, then the convention is to end the file with .json instead of .txt

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement