Storing default configurations in a js file

Storing default configurations in a js file

siddsidd Posts: 2Questions: 0Answers: 0
edited May 2013 in General
Hey there.

I have a small issue where I need to save dataTables configuration in a single js file so that I can include that file to get all my settings easily.
Here is what I have so far:
[code]
/* Set the defaults for DataTables initialisation */
$.extend( true, $.fn.dataTable.defaults, {
"iDisplayLength": 5
} );
... etc, etc ...
[/code]

The following code is where I create the table. How can I move the size and focus code into the settings file?
[code]
$(document).ready(function() {
$('#example').dataTable();
// Move this code into settings file
$('.dataTables_filter input').attr('size', '50').focus();
} );
[/code]

I have been searching for a solution, and I thought "fnInitComplete" would work, but it does not give me access to the dataTables object.
Here is a link to the example: http://live.datatables.net/ariqij/edit
Thanks in advance for any help.

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin
    > but it does not give me access to the dataTables object.

    You could use`settings.nTable` where `settings` is the first parameter passed into the fnInitComplete function. Its a 'private' settings property, but it is there.

    Allan
  • siddsidd Posts: 2Questions: 0Answers: 0
    Thanks for the super fast response Allan! You set me on the right track and it was `oSettings.nTableWrapper` that I was looking for. You can see the working example here:
    http://live.datatables.net/ariqij/2/edit
    The relevant code is:
    [code]
    /* Set the defaults for DataTables initialisation */
    $.extend( true, $.fn.dataTable.defaults, {
    "iDisplayLength": 5,
    "fnInitComplete": function ( oSettings, json ){
    $(oSettings.nTableWrapper)
    .find('.dataTables_filter input')
    .attr('size', '50')
    .focus();
    }
    } );
    [/code]

    The only drawback is that the first time the page is loaded, the changes don't appear until all your data is loaded, (which is a couple seconds in my case, if I load the entire data set) but it works.

    Thanks again.
This discussion has been closed.