数据表动态更改语言 [英] Datatables change language dynamically
本文介绍了数据表动态更改语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用具有数据表的表的jQuery语言进行更改。我试图按一个按钮来更改表格的语言。
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();
})
推荐答案
AFAIK没有内置的方法或插件(当前)动态切换语言。但是您可以做的是摧毁数据表并使用新的语言设置重新初始化。
AFAIK, there is no built-in method or plug-in (currently) to switch the language dynamically. But what you can do is destroy the datatable and re-initialize it with the new language setting.
所以,将按钮的点击处理程序更改为如下所示:
So, change your button's click handler to something like this:
$('#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演示。
这篇关于数据表动态更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文