How can I map a DataTable({data:...}) instance to the API syntax?
How can I map a DataTable({data:...}) instance to the API syntax?
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
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.
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
It might be tricky to replicate in an easy way. I was doing this within an IPython notebook which complicates the setup.