JQuery dataTables 1.10.5 custom properties

I am trying to set a custom property and be able to access it later. Is it possible, as I saw in the older version, you can use fnSettings, but how to use it in 1.10.5?

$('#table').DataTable({
        customProp: 'Hello World'
});

Then, by pressing a button, I thought I could do the following:

$('.test').on('click', function(e){
      var table = $('#table').DataTable();
      console.log(table.settings.oInit.customProp);
 }

However, I get: Uncaught TypeError: Can't read customProp property from undefined

Does anyone know how I can do this?

+4
source share
3 answers

You can use the jQuery method data()to store data in a related element. For instance:

$('#table').data('customProp', 'Hello World');

Later you can get it as shown below:

$('.test').on('click', function(e){
    console.log($('#table').data('customProp'));
}
+1
source

- table.settings.oInit . table.settings, $("#table").DataTable().settings oInit ( ). oInit :

var init;

$('#example').DataTable({
   customProp: 'Hello World',
   initComplete: function(settings) { 
       init = settings.oInit;
   }
});

:

alert(init.customProp);

demo (1.10.5) → http://jsfiddle.net/ajLe1484/

-, dataTables - "" . dataTables. 1.10.x - , , oInit 1.10.5.

+1

In DataTables 1.10.10 and later, the following will work:

$('#table').DataTable({
        customProp: 'Hello World'
});

console.log($('#table').DataTable().init().customProp);
+1
source

All Articles