Yes, this is core functionality of JavaScript itself. You simply need to be careful in how you structure things:
1. Default values can be stored in a separate .js, but you must load them before calling dataTable() on your table.
2. Make sure additional scripts (either in a separate file or right on the page) do not overwrite or null your defaults unless you want them to.
With Allan's help, I created a system for reusable defaults. In my case, they were for multiple tables on a single page, but you could do something similar for multiple tables across your application. Have a look and see if any of this is helpful: http://datatables.net/forums/comments.php?DiscussionID=4101&page=1#Item_10
I want to load the Dutch translation if datatables.php?lang=nl is loaded, and de English translation if ?lang=en is loaded. How do I do that?
With the famous jQuery Validate plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) you can just call the localisation file. For example: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/localization/messages_nl.js
In general, what I personally would do is store the language parameters as a variable in your separate JS files. So a tiny example of a file called language_es.js might look like:
[code]
var dt_translation = {
"oPaginate": {
"sFirst": "Primera Pagina"
},
"sEmptyTable": "No hay nada aqui!"
}
[/code]
Use PHP to get your query string variable, turn it into your separate JavaScript filename (for example, 'language_nl.js"), use PHP to then include this .js file into your page at an appropriate place, then write a function that takes your core initialization object and extends it using jQuery's .extend(), and then pass this new object into the dataTable()
Don't have the time to put together sample code right now, but it shouldn't be too hard if you still need help later.
There isn't a 'default-option'-function, like jQuery UI? Then you just can include:
[code]$.extend($.ui.dialog.prototype.options,
{
close:function(event, id)
{
$(this).dialog('destroy');
},
height: 300,
width: 400
});
[/code]
Currently no - however I'm in the middle of adding the ability to set defaults right now :-). This functionality will be in the 1.9 beta that I hope to release before too long.
Replies
Yes, this is core functionality of JavaScript itself. You simply need to be careful in how you structure things:
1. Default values can be stored in a separate .js, but you must load them before calling dataTable() on your table.
2. Make sure additional scripts (either in a separate file or right on the page) do not overwrite or null your defaults unless you want them to.
With Allan's help, I created a system for reusable defaults. In my case, they were for multiple tables on a single page, but you could do something similar for multiple tables across your application. Have a look and see if any of this is helpful: http://datatables.net/forums/comments.php?DiscussionID=4101&page=1#Item_10
With the famous jQuery Validate plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) you can just call the localisation file. For example: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/localization/messages_nl.js
[code]
var dt_translation = {
"oPaginate": {
"sFirst": "Primera Pagina"
},
"sEmptyTable": "No hay nada aqui!"
}
[/code]
Use PHP to get your query string variable, turn it into your separate JavaScript filename (for example, 'language_nl.js"), use PHP to then include this .js file into your page at an appropriate place, then write a function that takes your core initialization object and extends it using jQuery's .extend(), and then pass this new object into the dataTable()
Don't have the time to put together sample code right now, but it shouldn't be too hard if you still need help later.
[code]$.extend($.ui.dialog.prototype.options,
{
close:function(event, id)
{
$(this).dialog('destroy');
},
height: 300,
width: 400
});
[/code]
Allan