4

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

2
  • Are you using datatables with client side data or do you need to send parameters to the server? Commented Feb 27, 2015 at 0:34
  • Hmmm, no I don't need to send this params to the server, because I've already keep some values in localstorage as sortColumn, searchValue, page, pagesize... But, now I need keep a custom attribute. Commented Feb 27, 2015 at 3:47

1 Answer 1

3

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/

Sign up to request clarification or add additional context in comments.

1 Comment

I was trying to get the from from "settings.oApi.hasSomeValue"... I'm so noob! =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.