How to globaly localize jquery DataTables

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.

Answers


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();
} );

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.


Need Your Help

split PDF into multiple files in C#

c# pdf

We have a C# Windows service that currently processes all the PDFs by reading the 2D barcode on the PDF using a 3rd party component and then updates the database and stores the document in the Docu...