Override the oLanguage option in one place

Override the oLanguage option in one place

jpgraveljpgravel Posts: 2Questions: 0Answers: 0
edited April 2014 in Feature requests
Hi,

I use DataTables in my project and I coded everything in english at first to introduce the internationalization later. I'm using dataTable on a lot of tables in my web application and I don't want to change my code for every dataTable calls to add the oLanguage option parameter. This maybe a question more related to JavaScript and how jQuery extension works but it would be nice if I could just do someting like I did with jQuery-ui datePicker:

[code]
$.datepicker.regional['fr'] = { /* language definition object */ };
$.datepicker.regional['it'] = { /* language definition object */ };
$.datepicker.regional['de'] = { /* language definition object */ };
$.datepicker.regional['en'] = { /* language definition object */ };

// Sets the language depending on the user's settings
$.datepicker.setDefaults($.datepicker.regional[localStorage["settings.language"]]);
[/code]

The solution I seek should be done in my javascript files and leaves the original jquery.datatables.js file untouched. I'm sure there is an easy way to do that. It may be that I don't understand the datatable object structure yet.

Thanks

Replies

  • allanallan Posts: 63,630Questions: 1Answers: 10,488 Site admin
    You can set the default values in a single place:

    [code]
    $.extend( true, $.fn.dataTable.defaults.oLanguage, {
    ... // language options
    } );
    [/code]

    See: http://datatables.net/release-datatables/examples/advanced_init/defaults.html

    Allan
  • jpgraveljpgravel Posts: 2Questions: 0Answers: 0
    Works great, thanks!
This discussion has been closed.