Storing default configurations in a js file
Storing default configurations in a js file
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.
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.
This discussion has been closed.
Replies
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
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.