how to change language for DataTable

前端 未结 11 1775
灰色年华
灰色年华 2020-12-14 15:11

I store, in a session variable, which language does user wants to translate but I don\'t know to pass it DataTables

I found this explanation on the datatables websit

11条回答
  •  一个人的身影
    2020-12-14 15:53

    sorry to revive this thread, i know there is the solution, but it is easy to change the language with the datatables. Here, i leave you with my own datatable example.

    $(document).ready(function ()
    // DataTable
            var table = $('#tblUsuarios').DataTable({
                aoColumnDefs: [
                    {"aTargets": [0], "bSortable": true},
                    {"aTargets": [2], "asSorting": ["asc"], "bSortable": true},
                ],
                "language": {
                    "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json"
                }
    
        });
    

    The language you get from the following link:

    http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n

    Just replace the URL value in the language option with the one you like. Remember to always use the comma


    Worked for me, hope it will work for anyone.

    Best regards!

提交回复
热议问题