Legacy Settings for "dom" feature plugins?

Legacy Settings for "dom" feature plugins?

tyricectyricec Posts: 2Questions: 1Answers: 0

Hello,

To get practice, I'm working on creating a plugin that is like Table Tools to export data for a project. Currently, I ran into a
problem in figuring out how to get custom options from the table constructor object. Since I want to create a dom feature plugin,
I figured the settings object passed into fnInit would provide a way to use init() if passed to an api constructor. However,
the init function is not defined in this case.

  fnInit: function (settings) {
      var api = $.fn.dataTable.Api(settings);
      var customOption = api.init().customOption; // error: init not defined
  }

What I tried next was to check the init event on the api, but got the same results:

  fnInit: function (settings) {
    var api = $.fn.dataTable.Api(settings);
    api.on('init.dt', function (e, settings) {
     var api = $.fn.dataTableApi(settings); 
     var customOption = api.init().customOption; // error: init not defined
    });

After doing some investigation and finding the TableTools github, I found that this was accessed with the legacy version of oInit inside of the settings object:

  fnInit: function (settings) {
    var customOption = settings.customOption; // This works

My question is this is by default how it should work or was there a mistake in how I did this? I believe the callbacks for dom
features was not updated as other callbacks that take the Datatable.settings type allow the use of init(). An example is shown in the Datatable.settings type documentation

Any clues?

Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,920Questions: 1Answers: 10,151 Site admin
    Answer ✓

    I ran into a problem in figuring out how to get custom options from the table constructor object

    The init() method is provided for exactly this. You need DataTables 1.10.6+ which it sounds like you might have an older version.

    Allan

  • tyricectyricec Posts: 2Questions: 1Answers: 0

    Thanks @allan

    It was indeed 1.10.6 issue, I had 1.10.1. What was strange was that it worked in other cases except the dom element.

This discussion has been closed.