Reputation: 1230
I would like to know if there's a easy way to setup localization/translation into DataTables globaly.
It's just borring have to setup "languages": { "url": "/mytranslate.js" }
every time.
Upvotes: 0
Views: 585
Reputation: 58880
See Setting defaults article on how to apply initialization options globally.
This can be done using the
$.fn.dataTable.defaults
object. This object will take all of the same parameters as the DataTables initialisation object, but in this case you are setting the default for all future initialisations of DataTables.
For example:
$.extend( true, $.fn.dataTable.defaults, {
"language": {
"url": "/mytranslate.js"
}
} );
$(document).ready(function() {
$("#example").DataTable();
} );
Upvotes: 1
Reputation: 3
You could create a function to initialize the datatable, with the arguments you want to pass:
function dataTableInit(your_agruments) {
$('#example').dataTable({
"property": your_agruments,
"language": {
"url": "/mytranslate.js"
}
});
}
So you can reuse the function to initialize your Datatable and not have to set the language each time.
Upvotes: 0