Giolvani
Giolvani

Reputation: 629

Custom attribute jquery Datatables

I need create a custom attribute for my datatables instance, and I need keep this value, ex:

When I create an instance:

$('#table').dataTable({
    //common attributes
    ajax: 'url.json',
    columns: [...],
    //custom attribute
    hasSomeValueHere: 'helloword'
});

and I would like to keep it on settings of datatable, so if I check it will be there:

$('#table').dataTable({
    //common attributes
    ...
    fnDrawCallback: function(oSettings){
        alert(oSettings.hasSomeValueHere); //helloword
    }
});

There any way to extends datatable this way? Thanks

Upvotes: 4

Views: 2132

Answers (1)

davidkonrad
davidkonrad

Reputation: 85528

You dont need to extend dataTables for that. oSettings has an object, oInit, that holds the entire initialisation object, i.e the dataTables options. Example :

$('#example').dataTable({
    hasSomeValueHere: 'helloworld',
    fnDrawCallback: function(oSettings){
        alert(oSettings.oInit.hasSomeValueHere); //helloworld
    }
});

Demo -> http://jsfiddle.net/bvr2jk8z/


This works in 1.10.x as well, using DataTable()

$('#example').DataTable({
    hasSomeValueHere: 'helloworld',
    drawCallback: function(settings){
        alert(settings.oInit.hasSomeValueHere); //helloworld
    }
});

Demo -> http://jsfiddle.net/fkbtv1x7/

Upvotes: 3

Related Questions