How can I map a DataTable({data:...}) instance to the API syntax?

How can I map a DataTable({data:...}) instance to the API syntax?

kesmitkesmit Posts: 3Questions: 1Answers: 0

I'm trying to use DataTables in an environment with AMD, so I only have a handle to the object returned when the module is loaded. Normally when I create a table from JSON data, I would do the following:

var dt = $(table).DataTable({
data: [1, 2, 3] ,
columnDefs: [{ ... }, { ... }, { ... }]
});

However, when using require(...), I only have a handle to the datatables object. I don't see how to create the same structure as above. It appears as though I can get a handle to a table as follows, but I don't know how to load it with the data and columnDefs.

require(['datatables'], function (datatables) {
var dt = datatables.Api(table);
// How do I load data from data/columnDefs here?
});

Answers

  • kesmitkesmit Posts: 3Questions: 1Answers: 0

    It looks like my issue may have been with the order in which I required modules. If I add 'jquery' to the require list before 'datatables', then the jquery object has the DataTable object on it so I can use the first code sample above again.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Interesting, as DataTables requires jQuery, so it should be included automatically...

    Are you able to link to a page showing the issue? I know you have resolved it now, but it might still be interesting to debug if there is something wrong with DataTables.

    Allan

  • kesmitkesmit Posts: 3Questions: 1Answers: 0

    It might be tricky to replicate in an easy way. I was doing this within an IPython notebook which complicates the setup.

This discussion has been closed.