Topic: Cannot get Ajax Datatables to work with my API

Torroni pro asked 1 year ago

*_Expected behavior_* Datatables table displayed correctly and populated with json data returned by ajax call.

*_Actual behavior_* If I copy the example code from,the table works as expected (the column headings are displayed and when the response to the ajax call is received, the rows are populated with the json data).If however, I replace the test endpoint ( with my private API, the following happens:

  • the column headings are not displayed
  • the "no data found" message is displayed briefly
  • the rows remain empty

Using the browser developer tools, I have verified that the ajax call returns the json data in the correct format, but even if there was a problem with the json data, the column headings should be displayed.

My API is private, so I can't provide a public endpoint, but I copy here the result of the ajax call performed in the snippet:


Resources (screenshots, code snippets etc.)

Torroni pro answered 1 year ago

I have found the reason. The example uses a compact syntax:

const asyncTable = new mdb.Datatable(
  { columns, },
  { loading: true }

which only works if the variable referencing the array of column headings is called "columns". To use a different variable name, the full syntax must be used:

const asyncTable = new mdb.Datatable(
  { columns: inventoryTableColumns, },
  { loading: true }

I suggest to modify the example, using a variable name that is different from the name of the json key expected by the mdb.Datatable function. In the current example, both the variable and the json key are called "columns".

Grzegorz Bujański staff commented 1 year ago

Thanks for reporting. We will consider making this change to the documentation.

Please insert min. 20 characters.


Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.



Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 6.1.0
  • Device: laptop
  • Browser: Brave Browser Version 1.48.167 Chromium: 110.0.5481.104 (Official Build) (64-bit)
  • OS: Windows 10 Enterprise 22H2
  • Provided sample code: No
  • Provided link: Yes