How to implement interntionalization for jquery.datatable.min.js?

How to implement interntionalization for jquery.datatable.min.js?

suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0
edited December 2017 in Free community support

We have tried following code but it does not work.

$(document).ready(function () { $('#myTable').dataTable({ "language": { "url": "datatables-ch-zhs.json")" } }); });

We need to implement this on jquery.datatable.min.js

Answers

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    "datatables-ch-zhs.json"

    Do you actually have that file on your system?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    And what does it contain? Does the console in your browser show anything?

    Thanks,
    Allan

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0

    Yes I have that file in the same folder where cshtml resides. It contains following:
    {
    "sProcessing": "处理中...",
    "sLengthMenu": "显示 MENU 项结果",
    "sZeroRecords": "没有匹配结果",
    "sInfo": "显示第 STARTEND 项结果,共 TOTAL 项",
    "sInfoEmpty": "显示第 0 至 0 项结果,共 0 项",
    "sInfoFiltered": "(由 MAX 项结果过滤)",
    "sInfoPostFix": "",
    "sSearch": "搜索:",
    "sUrl": "",
    "sEmptyTable": "表中数据为空",
    "sLoadingRecords": "载入中...",
    "sInfoThousands": ",",
    "oPaginate": {
    "sFirst": "首页",
    "sPrevious": "上页",
    "sNext": "下页",
    "sLast": "末页"
    },
    "oAria": {
    "sSortAscending": ": 以升序排列此列",
    "sSortDescending": ": 以降序排列此列"
    }
    }

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0

    Browser shows default English which is hard coded in .js file

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0

    I am using jquery.datatable.min.js not jquery.datatable.js. In jquery.datatable.min.js "Showing 0 to 0 of 0 entries" is hard coded I guess

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0

    Even with jquery.datatable.js it takes default English

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    This example shows it working correctly. You'd need to give us a link to a page showing the issue, or create a test case showing the issue, so we can offer any support with it.

    Allan

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0

    This example does not work in cshtml page.

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0
    • File: jquery.dataTables.min.js
    • Version: 1.8.2
    • Author: Allan Jardine (www.sprymedia.co.uk)
    • Info: www.datatables.net

    We have implemented datatable Version 1.8.2. in cshtml file. When we try to implement interntionalization of datatable , it does not work.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    1.8.2 is very old and no longer supported. 1.10.16 is the current release, which you can download from here.

    Allan

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0

    Hi Allan,
    What is the minimum version that would work with internationalisation?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    1.8.2 can be used with internationalisation. Documentation for it is here.

    Allan

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0
    edited January 2018

    Hi Allan,
    We are on 1.8.2
    Our Table structure is as follows:

    <script id="tmplexample" type="text/x-jquery-tmpl">
        <div class="ui-corner-all ui-widget" id="divexample">
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
                <thead>\
    .
    ,
    ,
    

    We added following code for Internationalization:

    <script type="text/javascript">
        $(document).ready(function () {
               $('#example').DataTable({
                    "oLanguage": {
                        "sUrl": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json"
                        
                    }
                });
            });
    
        </script>
    

    It does not load the table.
    Can you please adv us on where are we wrong?
    Please also advise us on upgrading it to 1.10.16. Which all js files have to be upgraded to which version?
    Just by including https://code.jquery.com/jquery-1.12.4.js and replacing jquery.dataTables.min.js with 1.10.16 version did not work.

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Can you please adv us on where are we wrong?

    Your code looks fine to me - I'd need a link to a test case showing the issue to be able to help.

    Please also advise us on upgrading it to 1.10.16

    Upgrade documentation is available here. Yes, you should just need to update the DataTables JS file. Again, if that doesn't work for you I would need a link to a page showing the issue.

    Allan

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0
    edited January 2018

    Hi Allan,
    I found out the real issue.
    Our Datatable is wrapped inside script block:

    <script id="tmplexample" type="text/x-jquery-tmpl">
        <div class="ui-corner-all ui-widget" id="divexample">
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    

    So the following JQuery Script is not getting the table. If we remove Script block, Internationalisation works. But Script block is required to get data from database.

    <script type="text/javascript">
        $(document).ready(function () {
               $('#example').DataTable({
                    "oLanguage": {
                        "sUrl": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json"
                         
                    }
                });
            });
     
        </script>
    

    We tried following which did not work:

    <script type="text/javascript">
        $(document).ready(function () {
               $('#tmplexample .example').DataTable({
                    "oLanguage": {
                        "sUrl": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json"
                         
                    }
                });
            });
     
        </script>
    

    Can you please adv?

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    That would really be a question for the maintainer of whatever templating library you are using. I've not seen HTML inside a script tag before like that.

    Allan

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0

    Hi Allan,
    Any datatable object added to the DOM via another script cannot be accessed by jscirpt?
    Can you advise on how to address this?

    Thanks

  • suprithasraoasuprithasraoa Posts: 12Questions: 1Answers: 0
    {{each(i,item) List}} {{/each}}
    Name
    ${ item.Name }

    This is how data is populated in the datatable.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    I'm afraid I don't really understand the question. row().node() can be used to get the row node(s).

    Allan

This discussion has been closed.