我正在尝试使用带有数据表的表的jQuery语言进行更改。我正试图按一个按钮来改变表格的语言。
$('#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();
})
答案 0 :(得分:1)
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.
}
});
答案 1 :(得分:1)
正如原始海报所述,这不起作用:
tablacliente.fnSettings().oLanguage = espanol; // does not work!
但这样的事情应该有效,而不必破坏表格:
var oLanguage = tablacliente.fnSettings().oLanguage;
for (var field in espanol) {
oLanguage[field] = espanol[field];
}
答案 2 :(得分:0)
试试这个:
tablacliente.fnSettings()。oLanguage = espanol; tablacliente.fnUpdate();
适合我。
答案 3 :(得分:0)
<?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>