3

I'm trying to change with jQuery language of a table with datatables. I'm trying to push a button to change the language of the table.

$('#prueba').live('click', function () {
var espanol = {
     "sProcessing": "Procesando...",
     "sLengthMenu": "Mostrar _MENU_ registros",
     "sZeroRecords": "No se encontraron resultados",
     "sInfo": "Mostrando desde _START_ hasta _END_ de _TOTAL_ registros",
     "sInfoEmpty": "No existen registros",
     "sInfoFiltered": "(filtrado de un total de _MAX_ líneas)",
     "sInfoPostFix": "",
     "sSearch": "Buscar:",
     "sUrl": "",
"oPaginate": {
"sFirst":    "Primero",
"sPrevious": "Anterior",
"sNext":     "Siguiente",
"sLast":     "Último"
}
};
tablacliente.fnSettings().oLanguage= espanol;
tablacliente.fnDraw();
})
4

4 回答 4

3

AFAIK,没有内置的方法或插件(当前)来动态切换语言。但是您可以做的是破坏数据表并使用新的语言设置重新初始化它。

因此,将按钮的单击处理程序更改为如下所示:

$('#prueba').click(function(){
    if (typeof tablacliente != 'undefined' && tablacliente != null)
    {
        tablacliente.fnDestroy(); //important! you have to destroy first or you'll get an alert-error.
        tablacliente = null;
        tablacliente = $('#table_id').dataTable( {"oLanguage": espanol} ); //don't forget to include any other settings, if you have.
    }
});

这是关于 jsFiddle 的演示

于 2013-01-17T02:04:58.787 回答
2

As the original poster mentioned, this does not work:

tablacliente.fnSettings().oLanguage = espanol;    // does not work!

but something like this should work, without having to destroy the table:

var oLanguage = tablacliente.fnSettings().oLanguage;
for (var field in espanol) {
    oLanguage[field] = espanol[field];
}
于 2014-04-17T15:48:23.927 回答
2
<?php
$countries = array (
    "tr-TR"=>"//cdn.datatables.net/plug-ins/1.10.16/i18n/Turkish.json",
    "de-DE" =>"//cdn.datatables.net/plug-ins/1.10.16/i18n/German.json",
    "es-ES"=>"//cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
);
?>
<script>
    var locale='<?php echo $countries[locale_get_default()];?>';
    $(document).ready(function () {
        $('#page-params').dataTable({
            responsive: true,
            "oLanguage": {
                "sUrl": locale
            }
        });
    });
</script>
于 2017-12-05T19:40:59.937 回答
0

尝试这个:

tablacliente.fnSettings().oLanguage=espanol; tablacliente.fnUpdate();

为我工作。

于 2016-11-22T12:52:47.527 回答