Internationalisation

Internationalisation

jiangdyjiangdy Posts: 6Questions: 0Answers: 0
edited March 2012 in DataTables 1.9
Dear Sir,
I want to change oLanguage's content dynamically. I use the following code. but only "sInfo" was changed. Could other properties be changed ?
Hope you would like to give me a help.
[code]
$(document).ready(function() {
var dt = $('#example').dataTable( {
"oLanguage": {
"sLengthMenu": "Display _MENU_ records per page",
"sZeroRecords": "Nothing found - sorry",
"sInfo": "Showing _START_ to _END_ of _TOTAL_ records",
"sInfoEmpty": "Showing 0 to 0 of 0 records",
"sInfoFiltered": "(filtered from _MAX_ total records)"
}
} );

$("#testA").click(function(){

var changeLan = {
"sProcessing": "Bitte warten...",
"sLengthMenu": "_MENU_ Eintrage anzeigen",
"sZeroRecords": "Keine Eintrage vorhanden.",
"sInfo": "_START_ bis _END_ von _TOTAL_ Eintragen",
"sInfoEmpty": "0 bis 0 von 0 Eintragen",
"sInfoFiltered": "(gefiltert von _MAX_ Eintragen)",
"sInfoPostFix": "",
"sSearch": "Suchen",
"sUrl": "",
"oPaginate": {
"sFirst": "Erster",
"sPrevious": "Zuruck",
"sNext": "Nachster",
"sLast": "Letzter"
}
};
$.extend( dt.dataTableSettings[0].oLanguage, changeLan);
dt.dataTableSettings[0].oInstance.fnDraw();
});

} );

[/code]

Replies

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Currently there is no method for dynamically changing the language in DataTables. If you want to do this you'd need to create an API plug-in to do it, as there is no method in DataTables for updating language strings that were set at initialisation time. This limitation also applies to many of the features which cannot have their state changed after initialisation.

    Allan
  • jiangdyjiangdy Posts: 6Questions: 0Answers: 0
    Dear Allan
    Thank you for your reply. Probably difficult for me to write my own API. I hope someday I can do it.
    I work in Tokyo. Datatables' code is still difficult for me to understand. I have two questions, hope you would like to teach me!

    One question is:
    why we can use code in the following way ? I just know I should use "$.fn.dataTableSettings" by the way of $("#id").dataTableSettings() ? Am I right ?
    [code]
    var dt = $('#example').dataTable(); .......;
    $.fn.dataTableSettings[0].oApi._fnDraw( $.fn.dataTableSettings[0] );
    [/code]

    Second question is:
    How can I catch the sort event of a column ? I want to sort a column by a checkbox that I added to that column. When I check that checkbox, and sort, the column will be sort by different column data.

    Thank you very much !
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    1. You could use it that way, but I'd suggest not - the functions which start with an underscore are "private" and shouldn't really be used externally. The API methods are documented here: http://datatables.net/api . For example to draw the table you would:

    [code]
    var dt = $('#example').dataTable(); .......;
    dt.fnDraw();
    [/code]

    2.

    > How can I catch the sort event of a column ? I want to sort a column by a checkbox that I added to that column. When I check that checkbox, and sort, the column will be sort by different column data.

    What you would need to do is unbind the default click listener that DataTables adds to the header cell, and then bind your own that will call fnSort with the sorting parameters you want, based on the condition of the checkbox.

    Nothing like diving in at the deep end :-)

    Allan
  • jiangdyjiangdy Posts: 6Questions: 0Answers: 0
    Dear Allan
    Thank you for your reply !
    You know for some guys (like me), diving into the code deeply is very difficult. You mind, your intelligence all are required. But anyway I will try my best to make something. And if I still use datatables you made l will let you know. Thank you for your great plug-in !
    Best regards

    ジャン
This discussion has been closed.